Browse Source

zlong转发增加bili

dodo hold 3 months ago
parent
commit
8a224b20b6

+ 18 - 22
src/views/settings/config.vue

@@ -37,8 +37,13 @@
 
                                     <a-form-item field="webook_forward_zlong" label="Zlong 转发渠道">
                                         <a-checkbox-group v-model="forwardChannelsModel">
-                                            <a-checkbox value="xhs">小红书</a-checkbox>
-                                            <a-checkbox value="ks">快手</a-checkbox>
+                                            <a-checkbox
+                                                v-for="channel in zlongForwardChannelOptions"
+                                                :key="channel.value"
+                                                :value="channel.value"
+                                            >
+                                                {{ channel.label }}
+                                            </a-checkbox>
                                         </a-checkbox-group>
                                         <template #extra>
                                             实际保存值:{{ formData.webook_forward_zlong || '未启用' }}
@@ -296,10 +301,17 @@ import {
     getConfig
 } from '@/api/taobao';
 import RegularTester from './components/regular-tester.vue';
+import {
+    buildZlongForwardChannelValue,
+    normalizeZlongForwardChannels,
+    zlongForwardChannelDefaultValue,
+    zlongForwardChannelOptions,
+} from './zlongForwardChannels';
 
 const { loading, setLoading } = useLoading(true);
 
 const formRef = ref<FormInstance>();
+
 const formData = ref<UpdateConfigModel>({
     cookie: '',
     blacklist_oaid: '',
@@ -348,31 +360,15 @@ const formData = ref<UpdateConfigModel>({
     ks_blacklist_regular: '',
     ksTestToken: '',
     ks_limit_per_oaid_24h: 0,
-    webook_forward_zlong: 'xhs,ks'
+    webook_forward_zlong: zlongForwardChannelDefaultValue
 
 });
 
-const defaultForwardChannels = ['xhs', 'ks'];
 const normalizeForwardChannels = (value?: string | string[]) => {
-    const list = Array.isArray(value)
-        ? value
-        : String(value || '')
-            .split(',')
-            .map((item) => item.trim())
-            .filter(Boolean);
-
-    const normalized = Array.from(
-        new Set(
-            list
-                .map((item) => item.toLowerCase())
-                .filter((item) => defaultForwardChannels.includes(item))
-        )
-    );
-
-    return normalized;
+    return normalizeZlongForwardChannels(value);
 };
 const buildForwardChannelValue = (value?: string | string[]) => {
-    return normalizeForwardChannels(value).join(',');
+    return buildZlongForwardChannelValue(value);
 };
 const forwardChannelsModel = computed<string[]>({
     get() {
@@ -429,7 +425,7 @@ const reset = async () => {
         config.tk_blacklist_regular = restoreJson(config.tk_blacklist_regular)
         config.multi_token_regular = restoreJson(config.multi_token_regular)
         config.webook_forward_zlong = buildForwardChannelValue(
-            config.webook_forward_zlong || (config as any).webook_xhs_zlong || defaultForwardChannels
+            config.webook_forward_zlong || (config as any).webook_xhs_zlong || zlongForwardChannelDefaultValue
         )
         formData.value = config
     }

+ 10 - 19
src/views/settings/xhsZlongReport.vue

@@ -174,6 +174,13 @@ import {
     type XhsZlongForwardReportRecord,
     type XhsZlongForwardReportSummary,
 } from '@/api/taobao';
+import {
+    zlongForwardChannelColorMap as channelColorMap,
+    zlongForwardChannelLabelMap as channelLabelMap,
+    zlongForwardChannelOptions as channelOptions,
+    zlongForwardChannelValues,
+    normalizeZlongForwardChannels,
+} from './zlongForwardChannels';
 
 const bucketLabelMap: Record<string, string> = {
     hour: '小时',
@@ -187,19 +194,6 @@ const bucketColorMap: Record<string, string> = {
     month: 'orange',
     year: 'purple',
 };
-const defaultChannels = ['xhs', 'ks'];
-const channelOptions = [
-    { label: '小红书', value: 'xhs' },
-    { label: '快手', value: 'ks' },
-];
-const channelLabelMap: Record<string, string> = {
-    xhs: '小红书',
-    ks: '快手',
-};
-const channelColorMap: Record<string, string> = {
-    xhs: 'red',
-    ks: 'blue',
-};
 
 const { loading, setLoading } = useLoading(false);
 const renderData = ref<XhsZlongForwardReportRecord[]>([]);
@@ -216,7 +210,7 @@ const summary = ref<XhsZlongForwardReportSummary>({
 });
 
 const formModel = reactive({
-    channels: [...defaultChannels],
+    channels: [...zlongForwardChannelValues],
     bucket_type: 'day',
 });
 
@@ -239,11 +233,8 @@ const pagination = reactive({
 
 const toNumber = (value: unknown) => Number(value || 0);
 const normalizeChannels = (channels?: string[]) => {
-    const list = (channels || [])
-        .map((item) => String(item || '').trim().toLowerCase())
-        .filter((item) => defaultChannels.includes(item));
-
-    return list.length > 0 ? Array.from(new Set(list)) : [...defaultChannels];
+    const list = normalizeZlongForwardChannels(channels);
+    return list.length > 0 ? list : [...zlongForwardChannelValues];
 };
 const buildChannelsValue = (channels?: string[]) => normalizeChannels(channels).join(',');
 const normalizeRecord = (item: XhsZlongForwardReportRecord): XhsZlongForwardReportRecord => ({

+ 44 - 0
src/views/settings/zlongForwardChannels.ts

@@ -0,0 +1,44 @@
+export const zlongForwardChannelOptions = [
+    { label: '小红书', value: 'xhs', color: 'red' },
+    { label: '快手', value: 'ks', color: 'blue' },
+    { label: 'bilibili', value: 'bili', color: 'arcoblue' },
+];
+
+export const zlongForwardChannelValues = zlongForwardChannelOptions.map((item) => item.value);
+export const zlongForwardChannelValueSet = new Set<string>(zlongForwardChannelValues);
+export const zlongForwardChannelDefaultValue = zlongForwardChannelValues.join(',');
+export const zlongForwardChannelLabelMap = zlongForwardChannelOptions.reduce<Record<string, string>>(
+    (map, item) => {
+        map[item.value] = item.label;
+        return map;
+    },
+    {}
+);
+export const zlongForwardChannelColorMap = zlongForwardChannelOptions.reduce<Record<string, string>>(
+    (map, item) => {
+        map[item.value] = item.color;
+        return map;
+    },
+    {}
+);
+
+export const normalizeZlongForwardChannels = (value?: string | string[]) => {
+    const list = Array.isArray(value)
+        ? value
+        : String(value || '')
+            .split(',')
+            .map((item) => item.trim())
+            .filter(Boolean);
+
+    return Array.from(
+        new Set(
+            list
+                .map((item) => item.toLowerCase())
+                .filter((item) => zlongForwardChannelValueSet.has(item))
+        )
+    );
+};
+
+export const buildZlongForwardChannelValue = (value?: string | string[]) => {
+    return normalizeZlongForwardChannels(value).join(',');
+};