feat 支持修改爬取配置
All checks were successful
Build image / build (push) Successful in 26s

This commit is contained in:
timerzz 2024-05-23 21:18:01 +08:00
parent 545797ef8d
commit e89dbd6fa5
2 changed files with 53 additions and 6 deletions

View File

@ -3,3 +3,5 @@ import {mande} from "mande";
const spider = mande('/api/v1/spider') const spider = mande('/api/v1/spider')
export const GetSpiderCfg = ()=> spider.get("cfg") export const GetSpiderCfg = ()=> spider.get("cfg")
export const SetSpiderCfg = (cfg)=> spider.post("cfg",cfg)

View File

@ -1,9 +1,11 @@
<template> <template>
<div class="h-full m-4 bg-white rounded-2 shadow-lg p-8 flex flex-col justify-between space-y-4 overscroll-auto"> <div class="h-full m-4 bg-white rounded-2 shadow-lg p-8 flex flex-col justify-between space-y-4 overscroll-auto">
<div class="flex justify-between"> <div class="flex justify-between">
<div class="flex items-center space-x-16"> <div class="flex items-center space-x-16">
<div>当前汇率<span class="text-xl">{{spiderCfg.exchangeRate}}</span></div> <div>当前汇率<span class="text-xl">{{spiderCfg.exchangeRate}}</span></div>
<div>当前默认运费<span class="text-xl">{{spiderCfg.freight}}</span></div> <div>当前默认运费<span class="text-xl">{{spiderCfg.freight}}</span></div>
<div>当前折扣<span class="text-xl">{{spiderCfg.discount}}% </span></div>
<FormOutlined class="cursor-pointer" @click="editSpiderCfg"/>
</div> </div>
<div class="flex space-x-4"> <div class="flex space-x-4">
<a-input placeholder="请输入关键词" v-model:value="query.keyword" @pressEnter="search"></a-input> <a-input placeholder="请输入关键词" v-model:value="query.keyword" @pressEnter="search"></a-input>
@ -117,6 +119,22 @@
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-modal> </a-modal>
<a-modal v-model:open="spiderCfgModal.visible" @ok="updateSpiderCfg" centered>
<template #title>
编辑
</template>
<a-form :model="spiderCfgModal.data" :labelCol="{span: 6}">
<a-form-item label="汇率">
<a-input-number v-model:value="spiderCfgModal.data.exchangeRate" :min="1" />
</a-form-item>
<a-form-item label="运费">
<a-input-number v-model:value="spiderCfgModal.data.freight" :min="1"/>
</a-form-item>
<a-form-item label="折扣">
<a-input-number addon-after="%" v-model:value="spiderCfgModal.data.discount" :min="1" :max="100"/>
</a-form-item>
</a-form>
</a-modal>
</template> </template>
<script setup> <script setup>
@ -124,10 +142,10 @@ import {computed, h, onMounted, reactive, ref} from "vue";
import {GetProduct, ListProducts, UpdateProduct} from "@/api/product.js"; import {GetProduct, ListProducts, UpdateProduct} from "@/api/product.js";
import moment from "moment/moment.js"; import moment from "moment/moment.js";
import { clone } from 'radash' import { clone } from 'radash'
import {LoadingOutlined, SaveOutlined,SettingOutlined,CaretUpOutlined,CaretDownOutlined} from "@ant-design/icons-vue"; import {LoadingOutlined, SaveOutlined,SettingOutlined,CaretUpOutlined,CaretDownOutlined, FormOutlined} from "@ant-design/icons-vue";
import {message, Modal} from "ant-design-vue"; import {message, Modal} from "ant-design-vue";
import {CreateWatcher} from "@/api/watcher.js"; import {CreateWatcher} from "@/api/watcher.js";
import {GetSpiderCfg} from "@/api/spider.js"; import {GetSpiderCfg, SetSpiderCfg} from "@/api/spider.js";
onMounted(()=>{ onMounted(()=>{
list() list()
@ -335,9 +353,10 @@ const PRICE_STATUS = {
DOWN: 2 DOWN: 2
} }
const spiderCfg = ref({ const spiderCfg = ref({
exchangeRate: 0, exchangeRate: 0,
freight: 0 freight: 0,
discount: 100
}) })
const loadSpiderCfg = ()=>{ const loadSpiderCfg = ()=>{
@ -367,6 +386,32 @@ const expand = (expanded, record)=>{
}) })
} }
} }
const spiderCfgModal = reactive({
data: {
exchangeRate: 0,
freight: 0,
discount: 100
},
visible: false,
})
const editSpiderCfg = ()=>{
spiderCfgModal.data = clone(spiderCfg.value)
spiderCfgModal.visible = true
}
const updateSpiderCfg = ()=>{
SetSpiderCfg(spiderCfgModal.data).then(res=>{
message.success('修改成功')
}).catch(err=>{
message.error('修改失败')
console.log(err)
}).finally(()=>{
spiderCfgModal.visible = false
loadSpiderCfg()
})
}
</script> </script>