list.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. :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="purple" v-else>爬虫</a-tag>
  121. </template>
  122. <template #description>
  123. {{ record.description }}
  124. </template>
  125. </a-list-item-meta>
  126. </template>
  127. <template #nodeName="{ record }">
  128. <a-tag color="gray">{{ record.end_point }} - {{ record.nodeName }} </a-tag>
  129. </template>
  130. <template #status="{ record }">
  131. <a-tag v-if="record.status" bordered color="green" @click="changeStatus(record.id, false)">
  132. <template #icon>
  133. <icon-check />
  134. </template>
  135. 在线
  136. </a-tag>
  137. <a-tag v-else bordered color="" @click="changeStatus(record.id, true)">
  138. <template #icon>
  139. <icon-stop />
  140. </template>
  141. 下线
  142. </a-tag>
  143. </template>
  144. <template #actions="{ record }">
  145. <a-tag v-if="record.enable_parse" size="small" bordered color="red"
  146. @click="changeAttr(record.id, 'enable_parse', false)">
  147. 转链
  148. </a-tag>
  149. <a-tag v-else size="small" bordered color="" @click="changeAttr(record.id, 'enable_parse', true)">
  150. 转链
  151. </a-tag>
  152. <span style="margin: 5px;">
  153. <a-tag v-if="record.enable_coupon" size="small" bordered color="orange"
  154. @click="changeAttr(record.id, 'enable_coupon', false)">
  155. 优惠券
  156. </a-tag>
  157. <a-tag v-else size="small" bordered color=""
  158. @click="changeAttr(record.id, 'enable_coupon', true)">
  159. 优惠券
  160. </a-tag>
  161. </span>
  162. </template>
  163. <template #time="{ record }">
  164. <div style="color:gray;">
  165. <div>注册:{{ dayjs(record.create_time).format('MM-DD HH:mm') }}</div>
  166. <div>更新:{{ dayjs(record.last_time).format('MM-DD HH:mm') }}</div>
  167. <div v-if="dayjs().diff(dayjs(record.login_time), 'hours') < 48">
  168. 登录:{{ dayjs(record.login_time).format('MM-DD HH:mm') }}</div>
  169. </div>
  170. </template>
  171. <template #summary-cell="{ column, record }">
  172. <div style="margin:10px auto" v-if="column.slotName == 'hourly_calls_limit'">
  173. {{ numberFormat(record.current_hourly_calls) }}
  174. </div>
  175. <div style="margin:10px auto" v-if="column.slotName == 'daily_calls_limit'">
  176. {{ numberFormat(record.current_daily_calls) }}
  177. </div>
  178. <template v-if="column.dataIndex == 'today_clickNum' ||
  179. column.dataIndex == 'today_orderNum' ||
  180. column.dataIndex == 'today_finishOrderNum' ||
  181. column.dataIndex == 'today_finishCosPrice'">
  182. <div>{{ numberFormat(record[column.dataIndex]) }}</div>
  183. </template>
  184. <template v-if="column.dataIndex == 'today_cosPrice' ||
  185. column.dataIndex == 'today_finishCosFee' ||
  186. column.dataIndex == 'today_cosFee'">
  187. <div>{{ amountFormat(record[column.dataIndex]) }}</div>
  188. </template>
  189. </template>
  190. <template #time_range="{ record }">
  191. <WorkHourModel :path="updatePath" :record="record" @change="search" />
  192. </template>
  193. <template #hourly_calls_limit="{ record }">
  194. <a-tag bordered
  195. :color="record.current_hourly_calls > record.hourly_calls_limit && record.hourly_calls_limit > 0 ? 'red' : ''">
  196. {{ record.current_hourly_calls }} /
  197. {{ record.hourly_calls_limit }}
  198. </a-tag>
  199. </template>
  200. <template #daily_calls_limit="{ record }">
  201. <a-tag bordered
  202. :color="record.current_daily_calls > record.daily_calls_limit && record.daily_calls_limit > 0 ? 'red' : ''">
  203. {{ record.current_daily_calls }} /
  204. {{ record.daily_calls_limit }}
  205. </a-tag>
  206. </template>
  207. </a-table>
  208. </a-card>
  209. </div>
  210. </template>
  211. <script lang="ts" setup>
  212. import { useRouter } from 'vue-router';
  213. import { computed, ref, reactive, watch, nextTick } from 'vue';
  214. import { useI18n } from 'vue-i18n';
  215. import dayjs from 'dayjs';
  216. import useLoading from '@/hooks/loading';
  217. import { queryJdPool, JdPoolRecord, JdPoolParams } from '@/api/jd';
  218. import { Pagination } from '@/types/global';
  219. import { Message } from '@arco-design/web-vue';
  220. import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
  221. import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
  222. import cloneDeep from 'lodash/cloneDeep';
  223. import Sortable from 'sortablejs';
  224. import { numberFormat, amountFormat } from '@/utils/util';
  225. import { UpdateAccountModel, UpdateAccount } from '@/api/app';
  226. import WorkHourModel from '@/components/WorkHourModel.vue';
  227. const updatePath = '/api/JdUnion/update';
  228. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  229. type Column = TableColumnData & { checked?: true };
  230. const generateFormModel = () => {
  231. return {
  232. name: '',
  233. lastTime: [],
  234. status: '',
  235. sort: 'status',
  236. order: 'descending',
  237. };
  238. };
  239. const router = useRouter();
  240. const { loading, setLoading } = useLoading(true);
  241. const { t } = useI18n();
  242. const renderData = ref<JdPoolRecord[]>([]);
  243. const formModel = ref(generateFormModel());
  244. const cloneColumns = ref<Column[]>([]);
  245. const showColumns = ref<Column[]>([]);
  246. const size = ref<SizeProps>('small');
  247. const basePagination: Pagination = {
  248. current: 1,
  249. pageSize: 50,
  250. };
  251. const pagination = reactive({
  252. ...basePagination,
  253. });
  254. const densityList = computed(() => [
  255. {
  256. name: t('searchTable.size.mini'),
  257. value: 'mini',
  258. },
  259. {
  260. name: t('searchTable.size.small'),
  261. value: 'small',
  262. },
  263. {
  264. name: t('searchTable.size.medium'),
  265. value: 'medium',
  266. },
  267. {
  268. name: t('searchTable.size.large'),
  269. value: 'large',
  270. },
  271. ]);
  272. const columns = computed<TableColumnData[]>(() => [
  273. {
  274. title: '#',
  275. dataIndex: 'index',
  276. slotName: 'index',
  277. width: 50,
  278. },
  279. {
  280. title: '账号名',
  281. dataIndex: 'name',
  282. slotName: 'name',
  283. width: 250,
  284. },
  285. {
  286. title: '工作时间',
  287. dataIndex: 'time_range',
  288. slotName: 'time_range',
  289. align: 'right',
  290. width: 200,
  291. },
  292. {
  293. title: '当日推广效果',
  294. children: [
  295. {
  296. title: '点击量',
  297. dataIndex: 'today_clickNum',
  298. width: 100,
  299. align: 'right',
  300. render: (e: any) => numberFormat(e.record.today_clickNum)
  301. },
  302. {
  303. title: '有效订单',
  304. dataIndex: 'today_orderNum',
  305. width: 100,
  306. align: 'right',
  307. render: (e: any) => numberFormat(e.record.today_orderNum)
  308. },
  309. {
  310. title: '订单金额',
  311. dataIndex: 'today_cosPrice',
  312. width: 150,
  313. align: 'right',
  314. render: (e: any) => amountFormat(e.record.today_cosPrice)
  315. },
  316. {
  317. title: '预估收入',
  318. dataIndex: 'today_cosFee',
  319. width: 150,
  320. align: 'right',
  321. render: (e: any) => amountFormat(e.record.today_cosFee)
  322. },
  323. //
  324. ]
  325. },
  326. {
  327. title: '小时调用',
  328. slotName: 'hourly_calls_limit',
  329. dataIndex: 'current_hourly_calls',
  330. align: 'right',
  331. width: 120,
  332. },
  333. {
  334. title: '当日调用',
  335. slotName: 'daily_calls_limit',
  336. dataIndex: 'current_daily_calls',
  337. align: 'right',
  338. width: 150,
  339. },
  340. {
  341. title: '运行节点',
  342. slotName: 'nodeName',
  343. width: 120,
  344. },
  345. {
  346. title: '状态',
  347. slotName: 'status',
  348. width: 100,
  349. },
  350. {
  351. title: '分类',
  352. slotName: 'actions',
  353. width: 200,
  354. align: 'center',
  355. },
  356. {
  357. title: '时间',
  358. slotName: 'time',
  359. width: 170,
  360. },
  361. ]);
  362. const statusOptions = computed<SelectOptionData[]>(() => [
  363. {
  364. label: '全部',
  365. value: '',
  366. },
  367. {
  368. label: '在线',
  369. value: 'online',
  370. },
  371. {
  372. label: '下线',
  373. value: 'offline',
  374. },
  375. ]);
  376. const fetchData = async (
  377. params: JdPoolParams = {
  378. current: 1,
  379. pageSize: 50,
  380. sort: 'status',
  381. order: 'descending',
  382. getTotal: true,
  383. }
  384. ) => {
  385. setLoading(true);
  386. try {
  387. const { data } = await queryJdPool(params);
  388. if (!data) return;
  389. // const { data } = await queryJdPool(params);
  390. renderData.value = data.list;
  391. pagination.current = data.page;
  392. pagination.total = data.count;
  393. } catch (err) {
  394. console.log(err);
  395. // you can report use errorHandler or other
  396. } finally {
  397. setLoading(false);
  398. }
  399. };
  400. const changeItem = async (data: JdPoolRecord) => {
  401. router.push({ name: 'updateCookies' });
  402. };
  403. const billView = async (data: JdPoolRecord) => {
  404. router.push({ name: 'taobao_bill_dailys', query: { name: data.company } });
  405. };
  406. const changeStatus = async (id: number, val: any) => {
  407. const args = {
  408. id,
  409. name: 'status',
  410. val
  411. } as UpdateAccountModel;
  412. setLoading(true);
  413. try {
  414. const { data } = await UpdateAccount(updatePath, args);
  415. console.log(data, data.msg);
  416. const msg = data.msg || '更新成功!';
  417. if (data.success) {
  418. Message.success(msg);
  419. fetchData();
  420. } else {
  421. Message.error(data.msg);
  422. }
  423. } catch (e) { console.log(e) }
  424. setLoading(false);
  425. };
  426. const changeAttr = async (id: number, name: string, val: any) => {
  427. const args = {
  428. id,
  429. name,
  430. val
  431. } as UpdateAccountModel;
  432. setLoading(true);
  433. try {
  434. const { data } = await UpdateAccount(updatePath, args);
  435. console.log(data, data.msg);
  436. const msg = data.msg || '更新成功!';
  437. if (data.success) {
  438. Message.success(msg);
  439. fetchData();
  440. } else {
  441. Message.error(data.msg);
  442. }
  443. } catch (e) { console.log(e) }
  444. setLoading(false);
  445. };
  446. const search = () => {
  447. fetchData({
  448. ...basePagination,
  449. ...formModel.value,
  450. } as unknown as JdPoolParams);
  451. };
  452. const onPageChange = (current: number) => {
  453. fetchData({ ...basePagination, current });
  454. };
  455. fetchData();
  456. const reset = () => {
  457. formModel.value = generateFormModel();
  458. };
  459. const handleSelectDensity = (
  460. val: string | number | Record<string, any> | undefined,
  461. e: Event
  462. ) => {
  463. size.value = val as SizeProps;
  464. };
  465. const handleChange = (
  466. checked: boolean | (string | boolean | number)[],
  467. column: Column,
  468. index: number
  469. ) => {
  470. if (!checked) {
  471. cloneColumns.value = showColumns.value.filter(
  472. (item) => item.dataIndex !== column.dataIndex
  473. );
  474. } else {
  475. cloneColumns.value.splice(index, 0, column);
  476. }
  477. };
  478. const exchangeArray = <T extends Array<any>>(
  479. array: T,
  480. beforeIdx: number,
  481. newIdx: number,
  482. isDeep = false
  483. ): T => {
  484. const newArray = isDeep ? cloneDeep(array) : array;
  485. if (beforeIdx > -1 && newIdx > -1) {
  486. // 先替换后面的,然后拿到替换的结果替换前面的
  487. newArray.splice(
  488. beforeIdx,
  489. 1,
  490. newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
  491. );
  492. }
  493. return newArray;
  494. };
  495. const popupVisibleChange = (val: boolean) => {
  496. if (val) {
  497. nextTick(() => {
  498. const el = document.getElementById(
  499. 'tableSetting'
  500. ) as HTMLElement;
  501. const sortable = new Sortable(el, {
  502. onEnd(e: any) {
  503. const { oldIndex, newIndex } = e;
  504. exchangeArray(cloneColumns.value, oldIndex, newIndex);
  505. exchangeArray(showColumns.value, oldIndex, newIndex);
  506. },
  507. });
  508. });
  509. }
  510. };
  511. watch(
  512. () => columns.value,
  513. (val) => {
  514. cloneColumns.value = cloneDeep(val);
  515. cloneColumns.value.forEach((item, index) => {
  516. item.checked = true;
  517. });
  518. showColumns.value = cloneDeep(cloneColumns.value);
  519. },
  520. { deep: true, immediate: true }
  521. );
  522. </script>
  523. <script lang="ts">
  524. export default {
  525. name: 'SearchTable',
  526. };
  527. </script>
  528. <style scoped lang="less">
  529. .container {
  530. padding: 0 20px 20px 20px;
  531. }
  532. :deep(.arco-table-th) {
  533. &:last-child {
  534. .arco-table-th-item-title {
  535. margin-left: 16px;
  536. }
  537. }
  538. }
  539. .action-icon {
  540. margin-left: 12px;
  541. cursor: pointer;
  542. }
  543. .active {
  544. color: #0960bd;
  545. background-color: #e3f4fc;
  546. }
  547. .setting {
  548. display: flex;
  549. align-items: center;
  550. width: 200px;
  551. .title {
  552. margin-left: 12px;
  553. cursor: pointer;
  554. }
  555. }
  556. </style>