配置统一token输入

This commit is contained in:
zhonghua.li
2026-05-28 22:01:07 +08:00
parent 7752c8b875
commit 543f7928d0
2 changed files with 103 additions and 1 deletions

View File

@@ -47,3 +47,13 @@ export function syncLbGoodsFromHxr(params) {
timeout: 120000
})
}
/** 按 total_money 从大到小抢购货品,可能较慢 */
export function rushBuyLbGoods(data) {
return request({
url: '/lbGoods/rush-buy',
method: 'post',
data,
timeout: 120000
})
}

View File

@@ -53,6 +53,12 @@
<el-card class="action-container" shadow="never">
<el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
<el-input
v-model="apiToken"
clearable
placeholder="Token可选未填使用系统默认"
style="width: 320px; margin-left: 12px; vertical-align: middle"
/>
<el-button
type="warning"
icon="el-icon-refresh"
@@ -62,6 +68,15 @@
>
同步货品
</el-button>
<el-button
type="danger"
icon="el-icon-shopping-cart-full"
:loading="rushBuyLoading"
style="margin-left: 12px"
@click="openRushBuyDialog"
>
帮我抢单
</el-button>
</el-card>
<el-card class="table-container" shadow="never">
@@ -120,6 +135,26 @@
/>
</el-card>
<el-dialog title="帮我抢单" :visible.sync="rushBuyDialogVisible" width="520px" @close="resetRushBuyForm">
<el-form ref="rushBuyFormRef" :model="rushBuyForm" :rules="rushBuyRules" label-width="130px">
<el-form-item label="最大抢单数量" prop="maxBuyCount">
<el-input-number
v-model="rushBuyForm.maxBuyCount"
:min="1"
:precision="0"
:step="1"
controls-position="right"
style="width: 100%"
placeholder="成功笔数达到该值后停止"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="rushBuyDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="rushBuyLoading" @click="submitRushBuy">开始抢单</el-button>
</div>
</el-dialog>
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="760px" @close="resetForm">
<el-form ref="dataForm" :model="form" :rules="formRules" label-width="110px">
<el-form-item label="商品ID" prop="id">
@@ -208,6 +243,7 @@ import {
addLbGoods,
deleteLbGoods,
getLbGoodsList,
rushBuyLbGoods,
syncLbGoodsFromHxr,
updateLbGoods
} from '@/api/lb-goods'
@@ -263,6 +299,27 @@ export default {
loading: false,
submitLoading: false,
syncLoading: false,
rushBuyLoading: false,
rushBuyDialogVisible: false,
apiToken: '',
rushBuyForm: {
maxBuyCount: 1
},
rushBuyRules: {
maxBuyCount: [
{ required: true, message: '请输入最大抢单数量', trigger: 'blur' },
{
validator: (rule, value, callback) => {
if (value === undefined || value === null || value < 1) {
callback(new Error('最大抢单数量必须大于 0'))
return
}
callback()
},
trigger: 'change'
}
]
},
list: [],
total: 0,
dialogVisible: false,
@@ -295,6 +352,10 @@ export default {
const value = headers && headers['X-Tenant-Id']
return value ? String(value).trim() : ''
},
getApiTokenParam() {
const token = (this.apiToken || '').trim()
return token ? { token } : {}
},
handleSyncFromHxr() {
const tenantId = this.getTenantIdFromBusinessHeaders()
if (!tenantId) {
@@ -302,7 +363,7 @@ export default {
return
}
this.syncLoading = true
syncLbGoodsFromHxr({ tenantId })
syncLbGoodsFromHxr({ tenantId, ...this.getApiTokenParam() })
.then((res) => {
const isSuccess = res && (res.success === true || res.code === 200 || res.code === 20000)
if (!isSuccess) {
@@ -316,6 +377,37 @@ export default {
this.syncLoading = false
})
},
openRushBuyDialog() {
this.rushBuyDialogVisible = true
this.$nextTick(() => {
this.$refs.rushBuyFormRef && this.$refs.rushBuyFormRef.clearValidate()
})
},
resetRushBuyForm() {
this.rushBuyForm = { maxBuyCount: 1 }
this.$refs.rushBuyFormRef && this.$refs.rushBuyFormRef.resetFields()
},
submitRushBuy() {
this.$refs.rushBuyFormRef.validate((valid) => {
if (!valid) return
const payload = { maxBuyCount: this.rushBuyForm.maxBuyCount, ...this.getApiTokenParam() }
this.rushBuyLoading = true
rushBuyLbGoods(payload)
.then((res) => {
const isSuccess = res && (res.success === true || res.code === 200 || res.code === 20000)
if (!isSuccess) {
this.$message.error((res && res.message) || '抢单失败')
return
}
this.$message.success((res && res.message) || '抢单完成')
this.rushBuyDialogVisible = false
this.fetchList()
})
.finally(() => {
this.rushBuyLoading = false
})
})
},
fetchList() {
this.loading = true
getLbGoodsList(this.buildListParams())