list.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['menu.jd', 'menu.jd.list']" />
  4. <a-card class="general-card" :title="$t('menu.jd.list')">
  5. <a-row>
  6. <a-col :flex="1">
  7. <a-form :model="formModel" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
  8. label-align="left">
  9. <a-row :gutter="16">
  10. <a-col :span="8">
  11. <a-form-item field="name" label="账号名">
  12. <a-input v-model="formModel.name" placeholder="输入关键词搜索" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="8">
  16. <a-form-item field="lastTime" :label="$t('searchTable.form.lastTime')">
  17. <a-range-picker v-model="formModel.lastTime" style="width: 100%" />
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="8">
  21. <a-form-item field="status" :label="$t('searchTable.form.status')">
  22. <a-select v-model="formModel.status" :options="statusOptions" :placeholder="$t('searchTable.form.selectDefault')
  23. " />
  24. </a-form-item>
  25. </a-col>
  26. </a-row>
  27. </a-form>
  28. </a-col>
  29. <a-divider style="height: 38px" direction="vertical" />
  30. <a-col :flex="'86px'" style="text-align: right">
  31. <a-space direction="vertical" :size="18">
  32. <a-button type="primary" @click="search">
  33. <template #icon>
  34. <icon-search />
  35. </template>
  36. {{ $t('searchTable.form.search') }}
  37. </a-button>
  38. </a-space>
  39. </a-col>
  40. </a-row>
  41. <a-divider style="margin-top: 0" />
  42. <a-row style="margin-bottom: 16px">
  43. <a-col :span="12">
  44. <a-space>
  45. <a-button type="primary">
  46. <template #icon>
  47. <icon-plus />
  48. </template>
  49. {{ $t('searchTable.operation.create') }}
  50. </a-button>
  51. </a-space>
  52. </a-col>
  53. <a-col :span="12" style="
  54. display: flex;
  55. align-items: center;
  56. justify-content: end;
  57. ">
  58. <a-tooltip :content="$t('searchTable.actions.refresh')">
  59. <div class="action-icon" @click="search"><icon-refresh size="18" /></div>
  60. </a-tooltip>
  61. <a-dropdown @select="handleSelectDensity">
  62. <a-tooltip :content="$t('searchTable.actions.density')">
  63. <div class="action-icon"><icon-line-height size="18" /></div>
  64. </a-tooltip>
  65. <template #content>
  66. <a-doption v-for="item in densityList" :key="item.value" :value="item.value"
  67. :class="{ active: item.value === size }">
  68. <span>{{ item.name }}</span>
  69. </a-doption>
  70. </template>
  71. </a-dropdown>
  72. <a-tooltip :content="$t('searchTable.actions.columnSetting')">
  73. <a-popover trigger="click" position="bl" @popup-visible-change="popupVisibleChange">
  74. <div class="action-icon"><icon-settings size="18" /></div>
  75. <template #content>
  76. <div id="tableSetting">
  77. <div v-for="(item, index) in showColumns" :key="item.dataIndex" class="setting">
  78. <div style="
  79. margin-right: 4px;
  80. cursor: move;
  81. ">
  82. <icon-drag-arrow />
  83. </div>
  84. <div>
  85. <a-checkbox v-model="item.checked" @change="
  86. handleChange(
  87. $event,
  88. item as TableColumnData,
  89. index
  90. )
  91. ">
  92. </a-checkbox>
  93. </div>
  94. <div class="title">
  95. {{
  96. item.title === '#'
  97. ? '序列号'
  98. : item.title
  99. }}
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. </a-popover>
  105. </a-tooltip>
  106. </a-col>
  107. </a-row>
  108. <a-table row-key="id" :loading="loading" :pagination="pagination" :summary="true" summary-text="汇总"
  109. :columns="(cloneColumns as TableColumnData[])" :data="renderData" :bordered="{ headerCell: true }"
  110. :row-class="getRowClass" :size="size" @page-change="onPageChange">
  111. <template #index="{ record }">
  112. {{ record.id }}
  113. </template>
  114. <template #name="{ record }">
  115. <a-list-item-meta>
  116. <template #title>
  117. {{ record.company }}
  118. <a-tag color="blue" v-if="record.work_mode == 1">网站推广</a-tag>
  119. <a-tag color="orange" v-else-if="record.work_mode == 2">媒体导购</a-tag>
  120. <a-tag color="blue" v-else-if="record.work_mode == 4">订单侠</a-tag>
  121. <a-tag color="purple" v-else>爬虫</a-tag>
  122. </template>
  123. <template #description>
  124. {{ record.description }}
  125. </template>
  126. </a-list-item-meta>
  127. </template>
  128. <template #nodeName="{ record }">
  129. <a-tag color="gray">{{ record.end_point }} - {{ record.nodeName }} </a-tag>
  130. </template>
  131. <template #status="{ record }">
  132. <a-tag v-if="record.status" bordered color="green" @click="changeStatus(record.id, false)">
  133. <template #icon>
  134. <icon-check />
  135. </template>
  136. 在线
  137. </a-tag>
  138. <a-tag v-else bordered color="" @click="changeStatus(record.id, true)">
  139. <template #icon>
  140. <icon-stop />
  141. </template>
  142. 下线
  143. </a-tag>
  144. </template>
  145. <template #actions="{ record }">
  146. <a-tag v-if="record.enable_parse" size="small" bordered color="red"
  147. @click="changeAttr(record.id, 'enable_parse', false)">
  148. 转链
  149. </a-tag>
  150. <a-tag v-else size="small" bordered color="" @click="changeAttr(record.id, 'enable_parse', true)">
  151. 转链
  152. </a-tag>
  153. <span style="margin: 5px;">
  154. <a-tag v-if="record.enable_coupon" size="small" bordered color="orange"
  155. @click="changeAttr(record.id, 'enable_coupon', false)">
  156. 优惠券
  157. </a-tag>
  158. <a-tag v-else size="small" bordered color=""
  159. @click="changeAttr(record.id, 'enable_coupon', true)">
  160. 优惠券
  161. </a-tag>
  162. </span>
  163. </template>
  164. <template #tags="{ record }">
  165. <a-tag v-if="record.parse_type" size="small" bordered color="blue">
  166. {{ record.parse_type }}
  167. </a-tag>
  168. </template>
  169. <template #time="{ record }">
  170. <div style="color:gray;">
  171. <div>注册:{{ dayjs(record.create_time).format('MM-DD HH:mm') }}</div>
  172. <div>更新:{{ dayjs(record.last_time).format('MM-DD HH:mm') }}</div>
  173. <div v-if="dayjs().diff(dayjs(record.login_time), 'hours') < 48">
  174. 登录:{{ dayjs(record.login_time).format('MM-DD HH:mm') }}</div>
  175. </div>
  176. </template>
  177. <template #summary-cell="{ column, record }">
  178. <div style="margin:10px auto" v-if="column.slotName == 'hourly_calls_limit'">
  179. {{ numberFormat(record.current_hourly_calls) }}
  180. </div>
  181. <div style="margin:10px auto" v-if="column.slotName == 'daily_calls_limit'">
  182. {{ numberFormat(record.current_daily_calls) }}
  183. </div>
  184. <template v-if="column.dataIndex == 'today_clickNum' ||
  185. column.dataIndex == 'today_orderNum' ||
  186. column.dataIndex == 'today_finishOrderNum' ||
  187. column.dataIndex == 'today_finishCosPrice'">
  188. <div>{{ numberFormat(record[column.dataIndex]) }}</div>
  189. </template>
  190. <template v-if="column.dataIndex == 'today_cosPrice' ||
  191. column.dataIndex == 'today_finishCosFee' ||
  192. column.dataIndex == 'today_cosFee'">
  193. <div>{{ amountFormat(record[column.dataIndex]) }}</div>
  194. </template>
  195. </template>
  196. <template #time_range="{ record }">
  197. <WorkHourModel :path="updatePath" :record="record" @change="search" />
  198. </template>
  199. <template #hourly_calls_limit="{ record }">
  200. <a-tag bordered
  201. :color="record.current_hourly_calls > record.hourly_calls_limit && record.hourly_calls_limit > 0 ? 'red' : ''">
  202. {{ record.current_hourly_calls }} /
  203. {{ record.hourly_calls_limit }}
  204. </a-tag>
  205. </template>
  206. <template #daily_calls_limit="{ record }">
  207. <a-tag bordered
  208. :color="record.current_daily_calls > record.daily_calls_limit && record.daily_calls_limit > 0 ? 'red' : ''">
  209. {{ record.current_daily_calls }} /
  210. {{ record.daily_calls_limit }}
  211. </a-tag>
  212. </template>
  213. </a-table>
  214. </a-card>
  215. </div>
  216. </template>
  217. <script lang="ts" setup>
  218. import { useRouter, useRoute } from 'vue-router';
  219. import { computed, ref, reactive, watch, nextTick } from 'vue';
  220. import { useI18n } from 'vue-i18n';
  221. import dayjs from 'dayjs';
  222. import useLoading from '@/hooks/loading';
  223. import { queryJdPool, JdPoolRecord, JdPoolParams } from '@/api/jd';
  224. import { Pagination } from '@/types/global';
  225. import { Modal, Message } from '@arco-design/web-vue';
  226. import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
  227. import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
  228. import cloneDeep from 'lodash/cloneDeep';
  229. import Sortable from 'sortablejs';
  230. import { numberFormat, amountFormat } from '@/utils/util';
  231. import { UpdateAccountModel, UpdateAccount } from '@/api/app';
  232. import WorkHourModel from '@/components/WorkHourModel.vue';
  233. const updatePath = '/api/JdUnion/update';
  234. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  235. type Column = TableColumnData & { checked?: true };
  236. const generateFormModel = () => {
  237. return {
  238. name: '',
  239. lastTime: [],
  240. status: '',
  241. show_hide: false,
  242. sort: 'status',
  243. order: 'descending',
  244. };
  245. };
  246. const router = useRouter();
  247. const route = useRoute();
  248. const { loading, setLoading } = useLoading(true);
  249. const { t } = useI18n();
  250. const renderData = ref<JdPoolRecord[]>([]);
  251. const formModel = ref(generateFormModel());
  252. const cloneColumns = ref<Column[]>([]);
  253. const showColumns = ref<Column[]>([]);
  254. const size = ref<SizeProps>('small');
  255. const basePagination: Pagination = {
  256. current: 1,
  257. pageSize: 500,
  258. };
  259. const pagination = reactive({
  260. ...basePagination,
  261. });
  262. const densityList = computed(() => [
  263. {
  264. name: t('searchTable.size.mini'),
  265. value: 'mini',
  266. },
  267. {
  268. name: t('searchTable.size.small'),
  269. value: 'small',
  270. },
  271. {
  272. name: t('searchTable.size.medium'),
  273. value: 'medium',
  274. },
  275. {
  276. name: t('searchTable.size.large'),
  277. value: 'large',
  278. },
  279. ]);
  280. const columns = computed<TableColumnData[]>(() => [
  281. {
  282. title: '#',
  283. dataIndex: 'index',
  284. slotName: 'index',
  285. width: 50,
  286. },
  287. {
  288. title: '账号名',
  289. dataIndex: 'name',
  290. slotName: 'name',
  291. width: 250,
  292. },
  293. {
  294. title: '',
  295. slotName: 'tags',
  296. width: 40,
  297. },
  298. {
  299. title: '工作时间',
  300. dataIndex: 'time_range',
  301. slotName: 'time_range',
  302. align: 'right',
  303. width: 200,
  304. },
  305. {
  306. title: '当日推广效果',
  307. children: [
  308. {
  309. title: '点击量',
  310. dataIndex: 'today_clickNum',
  311. width: 100,
  312. align: 'right',
  313. render: (e: any) => numberFormat(e.record.today_clickNum)
  314. },
  315. {
  316. title: '有效订单',
  317. dataIndex: 'today_orderNum',
  318. width: 100,
  319. align: 'right',
  320. render: (e: any) => numberFormat(e.record.today_orderNum)
  321. },
  322. {
  323. title: '订单金额',
  324. dataIndex: 'today_cosPrice',
  325. width: 150,
  326. align: 'right',
  327. render: (e: any) => amountFormat(e.record.today_cosPrice)
  328. },
  329. {
  330. title: '预估收入',
  331. dataIndex: 'today_cosFee',
  332. width: 150,
  333. align: 'right',
  334. render: (e: any) => amountFormat(e.record.today_cosFee)
  335. },
  336. //
  337. ]
  338. },
  339. {
  340. title: '小时调用',
  341. slotName: 'hourly_calls_limit',
  342. dataIndex: 'current_hourly_calls',
  343. align: 'right',
  344. width: 120,
  345. },
  346. {
  347. title: '当日调用',
  348. slotName: 'daily_calls_limit',
  349. dataIndex: 'current_daily_calls',
  350. align: 'right',
  351. width: 150,
  352. },
  353. {
  354. title: '运行节点',
  355. slotName: 'nodeName',
  356. width: 120,
  357. },
  358. {
  359. title: '状态',
  360. slotName: 'status',
  361. width: 100,
  362. },
  363. {
  364. title: '分类',
  365. slotName: 'actions',
  366. width: 200,
  367. align: 'center',
  368. },
  369. {
  370. title: '时间',
  371. slotName: 'time',
  372. width: 170,
  373. },
  374. ]);
  375. const statusOptions = computed<SelectOptionData[]>(() => [
  376. {
  377. label: '全部',
  378. value: '',
  379. },
  380. {
  381. label: '在线',
  382. value: 'online',
  383. },
  384. {
  385. label: '下线',
  386. value: 'offline',
  387. },
  388. ]);
  389. const getRowClass = (record: JdPoolRecord) => {
  390. return record.is_hide ? 'special-table-row' : '';
  391. };
  392. if (route.query.show_hide === '1') {
  393. formModel.value.show_hide = true;
  394. }
  395. const fetchData = async (
  396. params: JdPoolParams = {
  397. current: 1,
  398. pageSize: 50,
  399. show_hide: false,
  400. sort: 'status',
  401. order: 'descending',
  402. getTotal: true,
  403. }
  404. ) => {
  405. if (route.query.show_hide === '1') {
  406. params.show_hide = true;
  407. }
  408. setLoading(true);
  409. try {
  410. const { data } = await queryJdPool(params);
  411. if (!data) return;
  412. // const { data } = await queryJdPool(params);
  413. renderData.value = data.list;
  414. pagination.current = data.page;
  415. pagination.total = data.count;
  416. } catch (err) {
  417. console.log(err);
  418. // you can report use errorHandler or other
  419. } finally {
  420. setLoading(false);
  421. }
  422. };
  423. const changeItem = async (data: JdPoolRecord) => {
  424. router.push({ name: 'updateCookies' });
  425. };
  426. const billView = async (data: JdPoolRecord) => {
  427. router.push({ name: 'taobao_bill_dailys', query: { name: data.company } });
  428. };
  429. const changeStatus = async (id: number, val: any) => {
  430. const args = {
  431. id,
  432. name: 'status',
  433. val
  434. } as UpdateAccountModel;
  435. Modal.confirm({
  436. title: '确认提示',
  437. content: '确定要更改状态吗?',
  438. okText: '确认',
  439. cancelText: '取消',
  440. async onOk() {
  441. setLoading(true);
  442. try {
  443. const { data } = await UpdateAccount(updatePath, args);
  444. console.log(data, data.msg);
  445. const msg = data.msg || '更新成功!';
  446. if (data.success) {
  447. Message.success(msg);
  448. fetchData();
  449. } else {
  450. Message.error(data.msg);
  451. }
  452. } catch (e) { console.log(e) }
  453. setLoading(false);
  454. }
  455. });
  456. };
  457. const changeAttr = async (id: number, name: string, val: any) => {
  458. const args = {
  459. id,
  460. name,
  461. val
  462. } as UpdateAccountModel;
  463. Modal.confirm({
  464. title: '确认提示',
  465. content: '确定要更改状态吗?',
  466. okText: '确认',
  467. cancelText: '取消',
  468. async onOk() {
  469. setLoading(true);
  470. try {
  471. const { data } = await UpdateAccount(updatePath, args);
  472. console.log(data, data.msg);
  473. const msg = data.msg || '更新成功!';
  474. if (data.success) {
  475. Message.success(msg);
  476. fetchData();
  477. } else {
  478. Message.error(data.msg);
  479. }
  480. } catch (e) { console.log(e) }
  481. setLoading(false);
  482. }
  483. });
  484. };
  485. const search = () => {
  486. fetchData({
  487. ...basePagination,
  488. ...formModel.value,
  489. } as unknown as JdPoolParams);
  490. };
  491. const onPageChange = (current: number) => {
  492. fetchData({ ...basePagination, current });
  493. };
  494. fetchData();
  495. const reset = () => {
  496. formModel.value = generateFormModel();
  497. };
  498. const handleSelectDensity = (
  499. val: string | number | Record<string, any> | undefined,
  500. e: Event
  501. ) => {
  502. size.value = val as SizeProps;
  503. };
  504. const handleChange = (
  505. checked: boolean | (string | boolean | number)[],
  506. column: Column,
  507. index: number
  508. ) => {
  509. if (!checked) {
  510. cloneColumns.value = showColumns.value.filter(
  511. (item) => item.dataIndex !== column.dataIndex
  512. );
  513. } else {
  514. cloneColumns.value.splice(index, 0, column);
  515. }
  516. };
  517. const exchangeArray = <T extends Array<any>>(
  518. array: T,
  519. beforeIdx: number,
  520. newIdx: number,
  521. isDeep = false
  522. ): T => {
  523. const newArray = isDeep ? cloneDeep(array) : array;
  524. if (beforeIdx > -1 && newIdx > -1) {
  525. // 先替换后面的,然后拿到替换的结果替换前面的
  526. newArray.splice(
  527. beforeIdx,
  528. 1,
  529. newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
  530. );
  531. }
  532. return newArray;
  533. };
  534. const popupVisibleChange = (val: boolean) => {
  535. if (val) {
  536. nextTick(() => {
  537. const el = document.getElementById(
  538. 'tableSetting'
  539. ) as HTMLElement;
  540. const sortable = new Sortable(el, {
  541. onEnd(e: any) {
  542. const { oldIndex, newIndex } = e;
  543. exchangeArray(cloneColumns.value, oldIndex, newIndex);
  544. exchangeArray(showColumns.value, oldIndex, newIndex);
  545. },
  546. });
  547. });
  548. }
  549. };
  550. watch(
  551. () => columns.value,
  552. (val) => {
  553. cloneColumns.value = cloneDeep(val);
  554. cloneColumns.value.forEach((item, index) => {
  555. item.checked = true;
  556. });
  557. showColumns.value = cloneDeep(cloneColumns.value);
  558. },
  559. { deep: true, immediate: true }
  560. );
  561. </script>
  562. <script lang="ts">
  563. export default {
  564. name: 'SearchTable',
  565. };
  566. </script>
  567. <style scoped lang="less">
  568. .container {
  569. padding: 0 20px 20px 20px;
  570. }
  571. :deep(.arco-table-th) {
  572. &:last-child {
  573. .arco-table-th-item-title {
  574. margin-left: 16px;
  575. }
  576. }
  577. }
  578. .action-icon {
  579. margin-left: 12px;
  580. cursor: pointer;
  581. }
  582. .active {
  583. color: #0960bd;
  584. background-color: #e3f4fc;
  585. }
  586. .setting {
  587. display: flex;
  588. align-items: center;
  589. width: 200px;
  590. .title {
  591. margin-left: 12px;
  592. cursor: pointer;
  593. }
  594. }
  595. :deep(.special-table-row td) {
  596. background-color: var(--color-warning-light-2) !important;
  597. }
  598. </style>