list.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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" @page-size-change="onPageSizeChange">
  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. <a-tag v-if="record.enable_sync_report" size="small" bordered color="blue"
  164. @click="changeAttr(record.id, 'enable_sync_report', false)">
  165. 同步收益
  166. </a-tag>
  167. <a-tag v-else size="small" bordered color="gray"
  168. @click="changeAttr(record.id, 'enable_sync_report', true)">
  169. 同步收益
  170. </a-tag>
  171. <span style="margin:0 5px;">
  172. <a-tag v-if="record.enable_sync_order" size="small" bordered color="arcoblue"
  173. @click="changeAttr(record.id, 'enable_sync_order', false)">
  174. 同步订单
  175. </a-tag>
  176. <a-tag v-else size="small" bordered color="gray"
  177. @click="changeAttr(record.id, 'enable_sync_order', true)">
  178. 同步订单
  179. </a-tag>
  180. </span>
  181. </template>
  182. <template #tags="{ record }">
  183. <a-tag v-if="record.parse_type" size="small" bordered color="blue">
  184. {{ record.parse_type }}
  185. </a-tag>
  186. <a-tag v-if="record.riskStrategy" size="small" bordered color="orange">
  187. {{ record.riskStrategy }}-{{ record.launchScene }}
  188. </a-tag>
  189. <a-tag v-if="record.riskCookie" size="small" bordered color="red">
  190. {{ record.riskCookie }}
  191. </a-tag>
  192. </template>
  193. <template #time="{ record }">
  194. <div style="color:gray;">
  195. <div>注册:{{ dayjs(record.create_time).format('MM-DD HH:mm') }}</div>
  196. <div>更新:{{ dayjs(record.last_time).format('MM-DD HH:mm') }}</div>
  197. <div v-if="dayjs().diff(dayjs(record.login_time), 'hours') < 48">
  198. 登录:{{ dayjs(record.login_time).format('MM-DD HH:mm') }}</div>
  199. </div>
  200. </template>
  201. <template #summary-cell="{ column, record }">
  202. <div style="margin:10px auto" v-if="column.slotName == 'hourly_calls_limit'">
  203. {{ numberFormat(record.current_hourly_calls) }}
  204. </div>
  205. <div style="margin:10px auto" v-if="column.slotName == 'daily_calls_limit'">
  206. {{ numberFormat(record.current_daily_calls) }}
  207. </div>
  208. <template v-if="column.dataIndex == 'today_clickNum' ||
  209. column.dataIndex == 'today_orderNum' ||
  210. column.dataIndex == 'today_finishOrderNum' ||
  211. column.dataIndex == 'today_finishCosPrice'">
  212. <div>{{ numberFormat(record[column.dataIndex]) }}</div>
  213. </template>
  214. <template v-if="column.dataIndex == 'today_cosPrice' ||
  215. column.dataIndex == 'today_finishCosFee' ||
  216. column.dataIndex == 'today_cosFee'">
  217. <div>{{ amountFormat(record[column.dataIndex]) }}</div>
  218. </template>
  219. </template>
  220. <template #time_range="{ record }">
  221. <WorkHourModel :path="updatePath" :record="record" @change="search" />
  222. </template>
  223. <template #hourly_calls_limit="{ record }">
  224. <a-tag bordered
  225. :color="record.current_hourly_calls > record.hourly_calls_limit && record.hourly_calls_limit > 0 ? 'red' : ''">
  226. {{ record.current_hourly_calls }} /
  227. {{ record.hourly_calls_limit }}
  228. </a-tag>
  229. </template>
  230. <template #daily_calls_limit="{ record }">
  231. <a-tag bordered
  232. :color="record.current_daily_calls > record.daily_calls_limit && record.daily_calls_limit > 0 ? 'red' : ''">
  233. {{ record.current_daily_calls }} /
  234. {{ record.daily_calls_limit }}
  235. </a-tag>
  236. </template>
  237. </a-table>
  238. </a-card>
  239. </div>
  240. </template>
  241. <script lang="ts" setup>
  242. import { useRouter, useRoute } from 'vue-router';
  243. import { computed, ref, reactive, watch, nextTick } from 'vue';
  244. import { useI18n } from 'vue-i18n';
  245. import dayjs from 'dayjs';
  246. import useLoading from '@/hooks/loading';
  247. import { queryJdPool, JdPoolRecord, JdPoolParams } from '@/api/jd';
  248. import { Pagination } from '@/types/global';
  249. import { Modal, Message } from '@arco-design/web-vue';
  250. import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
  251. import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
  252. import cloneDeep from 'lodash/cloneDeep';
  253. import Sortable from 'sortablejs';
  254. import { numberFormat, amountFormat } from '@/utils/util';
  255. import { UpdateAccountModel, UpdateAccount } from '@/api/app';
  256. import WorkHourModel from '@/components/WorkHourModel.vue';
  257. const updatePath = '/api/JdUnion/update';
  258. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  259. type Column = TableColumnData & { checked?: true };
  260. const generateFormModel = () => {
  261. return {
  262. name: '',
  263. lastTime: [],
  264. status: '',
  265. show_hide: false,
  266. sort: 'status',
  267. order: 'descending',
  268. };
  269. };
  270. const router = useRouter();
  271. const route = useRoute();
  272. const { loading, setLoading } = useLoading(true);
  273. const { t } = useI18n();
  274. const renderData = ref<JdPoolRecord[]>([]);
  275. const formModel = ref(generateFormModel());
  276. const cloneColumns = ref<Column[]>([]);
  277. const showColumns = ref<Column[]>([]);
  278. const size = ref<SizeProps>('small');
  279. const basePagination: Pagination = {
  280. current: 1,
  281. pageSize: 50,
  282. showPageSize: true,
  283. showTotal: true,
  284. pageSizeOptions: [10, 20, 50, 100, 200, 500]
  285. };
  286. const pagination = reactive({
  287. ...basePagination,
  288. });
  289. const densityList = computed(() => [
  290. {
  291. name: t('searchTable.size.mini'),
  292. value: 'mini',
  293. },
  294. {
  295. name: t('searchTable.size.small'),
  296. value: 'small',
  297. },
  298. {
  299. name: t('searchTable.size.medium'),
  300. value: 'medium',
  301. },
  302. {
  303. name: t('searchTable.size.large'),
  304. value: 'large',
  305. },
  306. ]);
  307. const columns = computed<TableColumnData[]>(() => [
  308. {
  309. title: '#',
  310. dataIndex: 'index',
  311. slotName: 'index',
  312. width: 50,
  313. },
  314. {
  315. title: '账号名',
  316. dataIndex: 'name',
  317. slotName: 'name',
  318. width: 250,
  319. },
  320. {
  321. title: '',
  322. slotName: 'tags',
  323. width: 40,
  324. },
  325. {
  326. title: '工作时间',
  327. dataIndex: 'time_range',
  328. slotName: 'time_range',
  329. align: 'right',
  330. width: 200,
  331. },
  332. {
  333. title: '当日推广效果',
  334. children: [
  335. {
  336. title: '点击量',
  337. dataIndex: 'today_clickNum',
  338. width: 100,
  339. align: 'right',
  340. render: (e: any) => numberFormat(e.record.today_clickNum)
  341. },
  342. {
  343. title: '有效订单',
  344. dataIndex: 'today_orderNum',
  345. width: 100,
  346. align: 'right',
  347. render: (e: any) => numberFormat(e.record.today_orderNum)
  348. },
  349. {
  350. title: '订单金额',
  351. dataIndex: 'today_cosPrice',
  352. width: 150,
  353. align: 'right',
  354. render: (e: any) => amountFormat(e.record.today_cosPrice)
  355. },
  356. {
  357. title: '预估收入',
  358. dataIndex: 'today_cosFee',
  359. width: 150,
  360. align: 'right',
  361. render: (e: any) => amountFormat(e.record.today_cosFee)
  362. },
  363. //
  364. ]
  365. },
  366. {
  367. title: '小时调用',
  368. slotName: 'hourly_calls_limit',
  369. dataIndex: 'current_hourly_calls',
  370. align: 'right',
  371. width: 120,
  372. },
  373. {
  374. title: '当日调用',
  375. slotName: 'daily_calls_limit',
  376. dataIndex: 'current_daily_calls',
  377. align: 'right',
  378. width: 150,
  379. },
  380. {
  381. title: '运行节点',
  382. slotName: 'nodeName',
  383. width: 120,
  384. },
  385. {
  386. title: '状态',
  387. slotName: 'status',
  388. width: 100,
  389. },
  390. {
  391. title: '分类',
  392. slotName: 'actions',
  393. width: 200,
  394. align: 'center',
  395. },
  396. {
  397. title: '时间',
  398. slotName: 'time',
  399. width: 170,
  400. },
  401. ]);
  402. const statusOptions = computed<SelectOptionData[]>(() => [
  403. {
  404. label: '全部',
  405. value: '',
  406. },
  407. {
  408. label: '在线',
  409. value: 'online',
  410. },
  411. {
  412. label: '下线',
  413. value: 'offline',
  414. },
  415. ]);
  416. const getRowClass = (record: JdPoolRecord) => {
  417. return record.is_hide ? 'special-table-row' : '';
  418. };
  419. if (route.query.show_hide === '1') {
  420. formModel.value.show_hide = true;
  421. }
  422. const fetchData = async (
  423. params: JdPoolParams = {
  424. current: 1,
  425. pageSize: 50,
  426. show_hide: false,
  427. sort: 'status',
  428. order: 'descending',
  429. getTotal: true,
  430. }
  431. ) => {
  432. if (route.query.show_hide === '1') {
  433. params.show_hide = true;
  434. }
  435. setLoading(true);
  436. try {
  437. const { data } = await queryJdPool(params);
  438. if (!data) return;
  439. // const { data } = await queryJdPool(params);
  440. renderData.value = data.list;
  441. pagination.current = data.page;
  442. pagination.total = data.count;
  443. } catch (err) {
  444. console.log(err);
  445. // you can report use errorHandler or other
  446. } finally {
  447. setLoading(false);
  448. }
  449. };
  450. const changeItem = async (data: JdPoolRecord) => {
  451. router.push({ name: 'updateCookies' });
  452. };
  453. const billView = async (data: JdPoolRecord) => {
  454. router.push({ name: 'taobao_bill_dailys', query: { name: data.company } });
  455. };
  456. const changeStatus = async (id: number, val: any) => {
  457. const args = {
  458. id,
  459. name: 'status',
  460. val
  461. } as UpdateAccountModel;
  462. Modal.confirm({
  463. title: '确认提示',
  464. content: '确定要更改状态吗?',
  465. okText: '确认',
  466. cancelText: '取消',
  467. async onOk() {
  468. setLoading(true);
  469. try {
  470. const { data } = await UpdateAccount(updatePath, args);
  471. console.log(data, data.msg);
  472. const msg = data.msg || '更新成功!';
  473. if (data.success) {
  474. Message.success(msg);
  475. search();
  476. } else {
  477. Message.error(data.msg);
  478. }
  479. } catch (e) { console.log(e) }
  480. setLoading(false);
  481. }
  482. });
  483. };
  484. const changeAttr = async (id: number, name: string, val: any) => {
  485. const args = {
  486. id,
  487. name,
  488. val
  489. } as UpdateAccountModel;
  490. Modal.confirm({
  491. title: '确认提示',
  492. content: '确定要更改状态吗?',
  493. okText: '确认',
  494. cancelText: '取消',
  495. async onOk() {
  496. setLoading(true);
  497. try {
  498. const { data } = await UpdateAccount(updatePath, args);
  499. console.log(data, data.msg);
  500. const msg = data.msg || '更新成功!';
  501. if (data.success) {
  502. Message.success(msg);
  503. search();
  504. } else {
  505. Message.error(data.msg);
  506. }
  507. } catch (e) { console.log(e) }
  508. setLoading(false);
  509. }
  510. });
  511. };
  512. const search = () => {
  513. fetchData({
  514. ...basePagination,
  515. ...formModel.value,
  516. } as unknown as JdPoolParams);
  517. };
  518. const onPageChange = (current: number) => {
  519. fetchData({
  520. ...basePagination,
  521. ...formModel.value,
  522. current
  523. } as unknown as JdPoolParams);
  524. };
  525. const onPageSizeChange = (current: number) => {
  526. basePagination.pageSize = current;
  527. pagination.pageSize = current;
  528. fetchData({
  529. ...basePagination,
  530. ...formModel.value,
  531. current: 1,
  532. } as unknown as JdPoolParams);
  533. };
  534. fetchData();
  535. const reset = () => {
  536. formModel.value = generateFormModel();
  537. };
  538. const handleSelectDensity = (
  539. val: string | number | Record<string, any> | undefined,
  540. e: Event
  541. ) => {
  542. size.value = val as SizeProps;
  543. };
  544. const handleChange = (
  545. checked: boolean | (string | boolean | number)[],
  546. column: Column,
  547. index: number
  548. ) => {
  549. if (!checked) {
  550. cloneColumns.value = showColumns.value.filter(
  551. (item) => item.dataIndex !== column.dataIndex
  552. );
  553. } else {
  554. cloneColumns.value.splice(index, 0, column);
  555. }
  556. };
  557. const exchangeArray = <T extends Array<any>>(
  558. array: T,
  559. beforeIdx: number,
  560. newIdx: number,
  561. isDeep = false
  562. ): T => {
  563. const newArray = isDeep ? cloneDeep(array) : array;
  564. if (beforeIdx > -1 && newIdx > -1) {
  565. // 先替换后面的,然后拿到替换的结果替换前面的
  566. newArray.splice(
  567. beforeIdx,
  568. 1,
  569. newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
  570. );
  571. }
  572. return newArray;
  573. };
  574. const popupVisibleChange = (val: boolean) => {
  575. if (val) {
  576. nextTick(() => {
  577. const el = document.getElementById(
  578. 'tableSetting'
  579. ) as HTMLElement;
  580. const sortable = new Sortable(el, {
  581. onEnd(e: any) {
  582. const { oldIndex, newIndex } = e;
  583. exchangeArray(cloneColumns.value, oldIndex, newIndex);
  584. exchangeArray(showColumns.value, oldIndex, newIndex);
  585. },
  586. });
  587. });
  588. }
  589. };
  590. watch(
  591. () => columns.value,
  592. (val) => {
  593. cloneColumns.value = cloneDeep(val);
  594. cloneColumns.value.forEach((item, index) => {
  595. item.checked = true;
  596. });
  597. showColumns.value = cloneDeep(cloneColumns.value);
  598. },
  599. { deep: true, immediate: true }
  600. );
  601. </script>
  602. <script lang="ts">
  603. export default {
  604. name: 'SearchTable',
  605. };
  606. </script>
  607. <style scoped lang="less">
  608. .container {
  609. padding: 0 20px 20px 20px;
  610. }
  611. :deep(.arco-table-th) {
  612. &:last-child {
  613. .arco-table-th-item-title {
  614. margin-left: 16px;
  615. }
  616. }
  617. }
  618. .action-icon {
  619. margin-left: 12px;
  620. cursor: pointer;
  621. }
  622. .active {
  623. color: #0960bd;
  624. background-color: #e3f4fc;
  625. }
  626. .setting {
  627. display: flex;
  628. align-items: center;
  629. width: 200px;
  630. .title {
  631. margin-left: 12px;
  632. cursor: pointer;
  633. }
  634. }
  635. :deep(.special-table-row td) {
  636. background-color: var(--color-warning-light-2) !important;
  637. }
  638. </style>