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
<template>
  <settings/>
  <fieldset>
    <legend>测试</legend>
    <div class="row">
      <button @click="fetchSearchTask">获取当前任务</button>
      <button @click="fetchSearchTaskAndCommit">获取当前任务并执行</button>
    </div>
    <div class="row">
      <label>输入:</label>
      <input v-model="input" list="search-conditions" type="search">
      <select v-model.number="stationId">
        <template v-for="([key, value]) of Object.entries(StationId)">
          <option v-if="!/^\d+$/.test(key)" :value="value">{{ key }}</option>
        </template>
      </select>
      <datalist id="search-conditions">
        <option :value="goodsId">随机详情ID</option>
        <option value="j1188114288">过期ID</option>
        <option value="BURBERRY ハンカチ">手帕</option>
        <option>PS5</option>
        <option>裤子</option>
      </datalist>
      <div></div>
    </div>
    <div class="row">
      <button @click="testDetail" :style="{visibility:stationId===StationId.YahooAuction?'visible':'hidden'}">
        获取输入详情
      </button>
      <button @click="testSearchOnce()">使用输入搜索</button>
    </div>
  </fieldset>
  <fieldset class="show-result">
    <legend>处理结果</legend>
    <a v-if="link" :href="link" target="_blank">验证链接</a>
    <a v-if="link2" :href="link2" target="_blank">验证链接2</a>
    <pre v-text="result"></pre>
  </fieldset>
</template>
 
<script setup lang="ts">
import {createMsgMethodProxy} from "gs-br-ext";
import {ITestApi, StationId} from "/src-com";
import {watch} from 'vue'
import Settings from "./views/Settings.vue";
import {goodsIds} from "./test/goodsIds";
import {isString} from "gs-base";
 
const api = createMsgMethodProxy<ITestApi>(true);
 
const stationId = ref(StationId.Mercari)
const input = ref('')
const goodsId = ref('')
 
const result = ref('')
const link = ref('')
const link2 = ref('')
 
if (localStorage.searchConditions) {
  input.value = localStorage.searchConditions;
}
 
async function testSearchOnce() {
  await displayResult('开始搜索:' + input.value)
  try {
    const value = await api.testSearch({
      stationId: stationId.value,
      keyword: input.value,
    });
    await displayResult(value);
  } catch (e) {
    await displayResult({
      error: `请检查node client 是否运行:${e.message}`
    });
  }
}
 
async function fetchSearchTask() {
  await displayResult('开始执行:fetchSearchTask')
  const task = await api.fetchTask();
  await displayResult(task);
}
 
async function fetchSearchTaskAndCommit() {
  await displayResult('开始执行:fetchSearchTaskAndCommit')
  const taskRv = await api.executeTask();
  await displayResult(taskRv);
}
 
async function testDetail() {
  await displayResult('正在获取详情:' + input.value)
  try {
    const value = await api.executeDetail(input.value);
    await displayResult(value);
  } catch (e) {
    await displayResult(`错误:\n${e.message}`)
  }
}
 
async function displayResult(data: any) {
  console.log(data)
  data || (data = `${data}`)
  if (isString(data)) {
    result.value = data;
    link.value = '';
    return;
  }
  if (data.link) {
    link.value = data.link;
    delete data.link;
  } else {
    link.value = '';
  }
  if (data.link2) {
    link2.value = data.link2;
    delete data.link2;
  } else {
    link2.value = '';
  }
  result.value = JSON.stringify(data, null, 2)
}
 
function randomGoodsId() {
  const r = Math.floor(Math.random() * goodsIds.length);
  goodsId.value = goodsIds[r];
}
 
randomGoodsId();
 
watch(() => input.value, randomGoodsId)
watch(input, v => {
  localStorage.searchConditions = v
})
 
</script>