lefengyang
2026-08-20 d01a28cb030b2cb0ff1d42273c877a0f728519a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<template>
  <fieldset>
    <legend>设置</legend>
    <div class="row">
      <label>
        <input type="checkbox"
               v-model="enableAutoTask"
               @change="saveCheckBox($event,EnableAutoTaskKey)"
        >
        开启《搜索》轮询
      </label>
      <label>
        缓存
        <select v-model="cache" @change="saveSelect($event,CacheKey)">
          <option :value="v" v-for="v of ['default','force-cache']">{{ v }}</option>
        </select>
      </label>
      <hr width="100%"/>
      <label>
        <input type="checkbox"
               v-model="reserve"
               @change="saveCheckBox($event,TaskReserveKey)"
        >
        测试时不标记任务
      </label>
      <label>
        任务类型
        <select v-model="taskType" @change="saveSelect($event,TaskTypeKey)">
          <option :value="row.value" v-for="row of taskTypeLabels">{{ row.label }}</option>
        </select>
      </label>
    </div>
  </fieldset>
  <fieldset>
    <legend>表单填写设置</legend>
    <div class="row">
      <label>
        <input type="checkbox"
               v-model="autoCloseTab"
               @change="saveCheckBox($event,AutoCloseTabKey)"
        >
        自动关闭标签
      </label>
      <label v-if="canHistoryMock">
        <input type="checkbox"
               :checked="useHistoryMock!==false"
               @change="useHistoryMock=$event.target.checked;saveCheckBox($event,UseHistoryMockKey)"
        >
        使用历史记录模拟数据
      </label>
      <template v-if="canHistoryMock && useHistoryMock!==false">
        <hr width="100%"/>
        <label>
          模拟数据目标
          &nbsp;
          <select id="history-select" @change="saveMockTarget">
            <option value="true">随机</option>
            <option
                v-for="item in history"
                :key="item.id"
                :value="item.id"
            >
              {{ item.name }} - {{ item.goodsId }}
            </option>
          </select>
        </label>
      </template>
    </div>
  </fieldset>
</template>
 
<script lang="ts" setup>
import {onMounted} from "vue";
import {StorageLocal} from "gs-br-ext";
import {
  AutoCloseTabKey,
  BidFormData,
  CacheKey,
  Db,
  EnableAutoTaskKey,
  TaskReserveKey, TaskType,
  TaskTypeKey,
  UseHistoryMockKey
} from "/src-com";
 
const enableAutoTask = ref(false)
const reserve = ref(false)
const autoCloseTab = ref(false)
const useHistoryMock = ref<boolean | number>(false)
const taskType = ref('')
const cache = ref('default')
const canHistoryMock = ref(false)
const history = ref<BidFormData[]>([]);
 
const taskTypeLabels: { value: TaskType|'', label: string }[] = [
  {value: '', label: '全部'},
  {value: 'bid', label: '仅拍卖'},
  {value: 'buyItNow', label: '仅一口价'},
  {value: 'search', label: '搜索'},
  {value: 'detail', label: '详情'},
]
 
onMounted(async () => {
  enableAutoTask.value = !!(await StorageLocal.getValue(EnableAutoTaskKey))
  reserve.value = !!(await StorageLocal.getValue(TaskReserveKey))
  autoCloseTab.value = !!(await StorageLocal.getValue(AutoCloseTabKey))
  useHistoryMock.value = !!(await StorageLocal.getValue(UseHistoryMockKey))
  taskType.value = await StorageLocal.getValue(TaskTypeKey) || ''
  const sc = await StorageLocal.getValue('cache');
  if (sc) {
    cache.value = sc
  }
  await Db.bidTaskAddedHistory.batchRead(async s => {
    canHistoryMock.value = await s.count() > 0;
    history.value = await s.all();
  })
})
 
async function saveCheckBox(e: any, key: string) {
  await StorageLocal.setValue(key, e.target.checked)
}
 
async function saveSelect(e: any, key: string) {
  await StorageLocal.setValue(key, e.target.value)
}
 
async function saveMockTarget(e: any) {
  let v: any = e.target.value;
  if (/^\d+$/.test(v)) {
    v = Number(v)
  } else {
    v = Boolean(v)
  }
  await StorageLocal.setValue(UseHistoryMockKey, v)
}
 
 
</script>