p_test.vue
4.86 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
<div style="margin-top: 1rem;">
<van-form @submit="onSubmit">
<van-cell-group inset>
<!-- <van-field
v-model="openid"
name="openid"
label="openid"
placeholder="openid"
/> -->
<van-field
v-model="fieldValue"
is-link
readonly
label="openid"
placeholder="选择openid"
@click="showPicker = true"
/>
<van-field
v-model="count"
name="count"
label="count"
placeholder="循环次数"
/>
<van-field
v-model="offset"
name="offset"
label="offset"
placeholder="起始值"
/>
</van-cell-group>
<div style="margin: 16px;">
<van-row gutter="20">
<van-col span="12">
<van-button round block type="primary" native-type="submit">
提交
</van-button>
</van-col>
<van-col span="12">
<van-button round block type="danger" @click="stop=true">
终止
</van-button>
</van-col>
</van-row>
</div>
</van-form>
<div style="padding: 1rem;">
<p>成功次数:{{ success_count }}</p>
<div>
<p>失败信息:</p>
<p v-for="(item, index) in error_msg" :key="index">{{ item }}</p>
</div>
<div>
<p>错误信息:</p>
<p v-for="(item, index) in fail_msg" :key="index">{{ item }}</p>
</div>
</div>
<van-popup v-model:show="showPicker" round position="bottom">
<van-picker
:columns="columns"
@cancel="showPicker = false"
@confirm="onConfirm"
/>
</van-popup>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import dayjs from 'dayjs';
import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
//import { } from '@/utils/generateModules.js'
//import { } from '@/utils/generateIcons.js'
//import { } from '@/composables'
const $route = useRoute();
const $router = useRouter();
useTitle($route.meta.title);
const openid = ref('');
const count = ref(null);
const offset = ref(0);
const success_count = ref(0);
const error_msg = ref([]);
const fail_msg = ref([]);
const stop = ref(false);
watch(
() => count.value,
() => {
if (!count.value) {
console.warn('开始时间', dayjs().format('HH:mm:ss'));
}
}
)
const onSubmit = async () => {
if (openid.value) {
// for (let i = offset.value; count.value > 0; i--) {
// count.value--;
// offset.value++;
// axios.get(`/srv/?a=no_auth_api&t=test_add_reserve&openid=${openid.value}&offset=${offset.value}`)
// .then(res => {
// if (res.data.code === 1) {
// success_count.value++;
// } else {
// error_msg.value.push(res.data.msg);
// }
// })
// .catch(err => {
// fail_msg.value.push(err);
// })
// .finally(() => { // 最终执行
// })
// await sleep(1); // 等待1毫秒
// if (stop.value) {
// break;
// }
// }
// 定义并发请求的 URL 列表
const urls = [
];
for (let i = offset.value; count.value > 0; i--) {
count.value--;
offset.value++;
urls.push(`/srv/?a=no_auth_api&t=test_add_reserve&openid=${openid.value}&offset=${offset.value}`);
await sleep(1); // 等待1毫秒
if (stop.value) {
break;
}
}
// 创建一个存储请求 Promise 的数组
const requests = urls.map(url => axios.get(url));
// 发送并发请求
Promise.all(requests)
.then(responses => {
// 处理所有请求的响应
responses.forEach(response => {
if (response.data.code === 1) {
success_count.value++;
} else {
error_msg.value.push(response.data.msg);
}
});
console.warn('结束时间', dayjs().format('HH:mm:ss'));
})
.catch(error => {
// 处理错误
console.log('请求出错:', error);
});
}
};
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
const columns = [
{ text: '李琛', value: 'o5CsxuLo0afvJXB8xu6quygh4MPY' },
{ text: '王鸿军', value: 'o5CsxuJLNcOYFPDDhO78q_jcIVQQ' },
{ text: 'Doris', value: 'o5CsxuI7VnvA1df1_Z6fjKm5fAQw' },
{ text: '胡一锐', value: 'o5CsxuF5AfUirRn4VUwaCSNZrUoM' },
{ text: '王佳琪', value: 'o5CsxuPn6EZ6_IMeCWJuxamDls1Y' },
{ text: '汪安军', value: 'o5CsxuEZkErN-51QKCb9r4LOCbtg' },
];
const showPicker = ref(false);
const fieldValue = ref('');
const onConfirm = ({ selectedOptions }) => {
showPicker.value = false;
fieldValue.value = selectedOptions[0].text;
openid.value = selectedOptions[0].value;
};
</script>
<style lang="less" scoped>
</style>