Explorar o código

京东联盟增加工作时间设置;

dodo hold %!s(int64=2) %!d(string=hai) anos
pai
achega
72a5096abe
Modificáronse 4 ficheiros con 182 adicións e 5 borrados
  1. 1 0
      src/api/jd.ts
  2. 156 0
      src/views/jd/components/WorkHourModel.vue
  3. 25 4
      src/views/jd/list.vue
  4. 0 1
      src/views/taobao/list.vue

+ 1 - 0
src/api/jd.ts

@@ -63,6 +63,7 @@ export interface JdPoolRecord {
     app_secret: string;
     user_agent: string;
     cookies: string;
+    time_range: number;
 }
 
 export interface JdPoolParams extends Partial<JdPoolRecord> {

+ 156 - 0
src/views/jd/components/WorkHourModel.vue

@@ -0,0 +1,156 @@
+<template>
+    <a-link type="text" @click="onClickSetWorkHour"> {{ formatWorkHours(record.time_range) }}</a-link>
+    <a-modal v-model:visible="showModel" title="设置工作时间" @cancel="handleCancel" @ok="handleOk">
+
+        <div style="margin-bottom:20px;">
+            <a-checkbox :model-value="checkedAll" :indeterminate="indeterminate" @change="handleChangeAll">全选
+            </a-checkbox>
+        </div>
+        <a-checkbox-group v-model="currentData" @change="handleChange">
+            <a-checkbox v-bind:key="h" v-for="h in defaultCheckedList" :value="h">{{ h }}</a-checkbox>
+        </a-checkbox-group>
+
+
+    </a-modal>
+</template>
+
+
+<script lang="ts" setup>
+/* eslint-disable no-bitwise, no-plusplus */
+
+import useLoading from '@/hooks/loading';
+import { defineProps, ref, reactive, defineEmits } from 'vue';
+import { JdUpdateAccountModel, JdUpdateAccount } from '@/api/jd';
+import { Message } from '@arco-design/web-vue';
+
+const { loading, setLoading } = useLoading(true);
+
+const props = defineProps<{
+    record: any;
+}>();
+
+const emits = defineEmits(['change']);
+
+
+const showModel = ref(false);
+
+const indeterminate = ref(false)
+const checkedAll = ref(false)
+const currentData = ref<string[]>([])
+
+const form = reactive({
+    id: 0,
+    tiem_range: 0
+});
+
+const defaultCheckedList = ref<string[]>(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09',
+    '10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
+    '20', '21', '22', '23',
+]);
+
+const handleChangeAll = (value: any) => {
+    console.log(value)
+    indeterminate.value = false;
+    if (value) {
+        checkedAll.value = true;
+        currentData.value = defaultCheckedList.value
+    } else {
+        checkedAll.value = false;
+        currentData.value = []
+    }
+}
+
+const handleChange = (values: any[]) => {
+    if (values.length === 3) {
+        checkedAll.value = true
+        indeterminate.value = false;
+    } else if (values.length === 0) {
+        checkedAll.value = false
+        indeterminate.value = false;
+    } else {
+        checkedAll.value = false
+        indeterminate.value = true;
+    }
+}
+
+
+const formatWorkHours = (workHours: number): string => {
+    if (workHours === 0) {
+        return '-';
+    }
+
+    if (workHours === (1 << 24) - 1) {
+        return '全天';
+    }
+
+    const hours: number[] = [];
+    for (let i = 0; i < 24; i++) {
+        if (workHours & (1 << i)) {
+            hours.push(i);
+        }
+    }
+
+    return hours.join(', ');
+};
+
+const onClickSetWorkHour = () => {
+    showModel.value = true
+};
+
+const handleCancel = () => {
+    showModel.value = true
+};
+
+
+const GetWorkHours = () => {
+    let hours = 0;
+    currentData.value.forEach(hour => {
+        const hourInt = parseInt(hour, 10);
+        hours |= (1 << hourInt);
+    });
+    return hours;
+}
+
+// 将工作时间的整数表示转换为小时字符串数组的函数
+const GenerateData = (hours: number): string[] => {
+    const generatedData: string[] = [];
+    for (let i = 0; i < 24; i++) {
+        if (hours & (1 << i)) {
+            generatedData.push(i.toString().padStart(2, '0'));
+        }
+    }
+    return generatedData;
+};
+currentData.value = GenerateData(props.record.time_range);
+handleChange(currentData.value)
+
+const handleOk = async () => {
+    console.log(currentData.value, GetWorkHours())
+    const timeRange = GetWorkHours()
+    const args = {
+        id: props.record.id,
+        name: "time_range",
+        val: timeRange
+    } as JdUpdateAccountModel;
+
+    setLoading(true);
+    try {
+
+        const { data } = await JdUpdateAccount(args);
+        console.log(data, data.msg);
+        const msg = data.msg || '更新成功!';
+        if (data.success) {
+            Message.success(msg);
+            showModel.value = false
+            emits('change', null);
+        } else {
+            Message.error(data.msg);
+        }
+    } catch (e) { console.log(e) }
+    setLoading(false);
+};
+
+
+
+
+</script>

+ 25 - 4
src/views/jd/list.vue

@@ -113,7 +113,17 @@
                     {{ record.id }}
                 </template>
                 <template #name="{ record }">
-                    <a-list-item-meta :title="record.company" :description="record.description" />
+                    <a-list-item-meta>
+                        <template #title>
+                            {{ record.company }}
+                            <a-tag color="blue" v-if="record.work_mode == 1">网站推广</a-tag>
+                            <a-tag color="orange" v-else-if="record.work_mode == 2">媒体导购</a-tag>
+                            <a-tag color="purple" v-else>爬虫</a-tag>
+                        </template>
+                        <template #description>
+                            {{ record.description }}
+                        </template>
+                    </a-list-item-meta>
                 </template>
                 <template #hourly_calls_limit="{ record }">
                     <a-tag bordered
@@ -182,8 +192,9 @@
                     <div style="margin:10px auto" v-if="column.slotName == 'daily_calls_limit'">
                         {{ numberFormat(record.current_daily_calls) }}
                     </div>
-
-
+                </template>
+                <template #time_range="{ record }">
+                    <WorkHourModel :record="record" @change="search" />
                 </template>
 
             </a-table>
@@ -205,6 +216,7 @@ import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
 import cloneDeep from 'lodash/cloneDeep';
 import Sortable from 'sortablejs';
 import { numberFormat, amountFormat } from '@/utils/util';
+import WorkHourModel from './components/WorkHourModel.vue';
 
 type SizeProps = 'mini' | 'small' | 'medium' | 'large';
 type Column = TableColumnData & { checked?: true };
@@ -266,6 +278,14 @@ const columns = computed<TableColumnData[]>(() => [
         title: '账号名',
         dataIndex: 'name',
         slotName: 'name',
+        width: 250,
+    },
+    {
+        title: '工作时间',
+        dataIndex: 'time_range',
+        slotName: 'time_range',
+        align: 'right',
+        width: 200,
     },
     {
         title: '小时调用',
@@ -278,7 +298,7 @@ const columns = computed<TableColumnData[]>(() => [
         slotName: 'daily_calls_limit',
         dataIndex: 'current_daily_calls',
         width: 150,
-    }, 
+    },
     {
         title: '运行节点',
         slotName: 'nodeName',
@@ -402,6 +422,7 @@ const changeAttr = async (id: number, name: string, val: any) => {
 
 
 
+
 const search = () => {
     fetchData({
         ...basePagination,

+ 0 - 1
src/views/taobao/list.vue

@@ -390,7 +390,6 @@ const billView = async (data: TkPoolRecord) => {
     router.push({ name: 'taobao_bill_dailys', query: { name: data.company } });
 };
 
-
 const changeStatus = async (id: number, val: any) => {
     const args = {
         id,