feat 可以添加邮箱推送
All checks were successful
Build image / build (push) Successful in 10m51s

This commit is contained in:
timerzz 2024-05-21 15:02:30 +08:00
parent 8ac08ece08
commit 1cfc9e0841
4 changed files with 74 additions and 45 deletions

View File

@ -8,4 +8,8 @@ export const ListPushers = (query) => {
export const AddPusher = (opt)=>{ export const AddPusher = (opt)=>{
return pushers.post(opt) return pushers.post(opt)
}
export const ListPusherOptions = ()=>{
return pushers.get('options')
} }

View File

@ -1,10 +1,4 @@
export const PUSHER = { export const PUSHER = {
ANPUSHER: 1, ANPUSHER: 1,
EMAIL:2
} }
export const WEBSITE_OPTIONS = [
{
label: 'anPush',
value: PUSHER.ANPUSHER
}
]

View File

@ -13,10 +13,7 @@
<a-table :dataSource="data.list" :columns="columns" :pagination="false"> <a-table :dataSource="data.list" :columns="columns" :pagination="false">
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'type'"> <template v-if="column.dataIndex === 'type'">
<span>{{WEBSITE_OPTIONS.find(w => w.value === record.type).label}}</span> <span>{{options.find(opt => opt.type === record.type).title}}</span>
</template>
<template v-if="column.dataIndex === 'updatedAt'">
<span>{{moment(record.updatedAt).format('YYYY-MM-DD HH:mm:ss')}}</span>
</template> </template>
<template v-if="column.dataIndex === 'option'"> <template v-if="column.dataIndex === 'option'">
<span>{{record.option}}</span> <span>{{record.option}}</span>
@ -30,21 +27,25 @@
<a-modal v-model:open="addModal.visible" title="添加推送通知" @ok="handleOk" > <a-modal v-model:open="addModal.visible" title="添加推送通知" @ok="handleOk" >
<a-spin :spinning="addModal.loading" :indicator="indicator"> <a-spin :spinning="addModal.loading" :indicator="indicator">
<a-form <a-form
ref="formRef"
:model="addModal.data" :model="addModal.data"
:label-col="{ span: 4 }" :label-col="{ span: 4 }"
:wrapper-col="{ span: 16 }" :wrapper-col="{ span: 16 }"
autocomplete="off" autocomplete="off"
@finish="closeAddModal" @finish="cleanAddModal"
@finishFailed="closeAddModal" @finishFailed="cleanAddModal"
> >
<a-form-item label="名称" name="name" :rules="[{ required: true, message: '请填写推送名称' }]"> <a-form-item label="名称" name="name" :rules="[{ required: true, message: '请填写推送名称' }]">
<a-input v-model:value="addModal.data.name" /> <a-input v-model:value="addModal.data.name" />
</a-form-item> </a-form-item>
<a-form-item label="token" name="option.token" :rules="[{ required: false, message: '请填写token' }]"> <a-form-item label="类型" name="type" :rules="[{ required: true, message: '请选择推送类型' }]">
<a-input v-model:value="addModal.data.option.token" /> <a-select v-model:value="addModal.data.type" @select="onSelectType">
<a-select-option v-for="opt in options" :value="opt.type">{{opt.title}}</a-select-option>
</a-select>
</a-form-item> </a-form-item>
<a-form-item label="channel" name="option.channel" :rules="[{ required: false, message: '请填写channel' }]"> <a-form-item v-for="item in addModal.formItems" :name="'option.' + item.param" :label="item.param">
<a-input v-model:value="addModal.data.option.channel" /> <a-input v-if="item.type === 'string'" v-model:value="addModal.data.option[item.param]"></a-input>
<a-input-number v-else-if="item.type.startsWith('int')" v-model:value="addModal.data.option[item.param]"></a-input-number>
</a-form-item> </a-form-item>
<a-form-item label="备注" name="remark"> <a-form-item label="备注" name="remark">
<a-textarea v-model:value="addModal.data.remark" /> <a-textarea v-model:value="addModal.data.remark" />
@ -56,17 +57,17 @@
<script setup> <script setup>
import {h, onMounted, reactive, ref} from "vue"; import {h, onMounted, reactive, ref} from "vue";
import {WEBSITE_OPTIONS} from "@/constants/website.js";
import moment from "moment/moment.js"; import moment from "moment/moment.js";
import {LoadingOutlined} from "@ant-design/icons-vue"; import {LoadingOutlined} from "@ant-design/icons-vue";
import {AddPusher, ListPushers} from "@/api/pusher.js"; import {AddPusher, ListPusherOptions, ListPushers} from "@/api/pusher.js";
import {PUSHER} from "@/constants/pusher.js";
import {message} from "ant-design-vue"; import {message} from "ant-design-vue";
import {clone} from "radash";
const loading = ref(false) const loading = ref(false)
onMounted(()=>{ onMounted(()=>{
list() list()
listOptions()
}) })
@ -100,39 +101,46 @@ const list = ()=>{
const addModal = reactive({ const addModal = reactive({
visible: false, visible: false,
data: { data: {
type:PUSHER.ANPUSHER, type:null,
name:'', name:'',
remark:'', remark:'',
option:{ option: {}
token:'',
channel: ''
}
}, },
formItems: [],
loading: false loading: false
}) })
const closeAddModal = ()=>{ const formRef = ref()
addModal.visible = false const cleanAddModal=()=>{
addModal.data = { addModal.data = {
type:PUSHER.ANPUSHER, type:null,
name:'', name:'',
remark:'', remark:'',
option:{ option: {}
token:'',
channel: ''
}
} }
addModal.formItems = []
formRef.value.clearValidate()
} }
const onSelectType = (value, option)=>{
addModal.formItems = options.value.find(o => o.type === value).formItems
}
const handleOk = ()=>{ const handleOk = ()=>{
AddPusher(addModal.data).then(res=>{ formRef.value.validateFields().then(res=>{
message.success("添加成功") const data = clone(addModal.data)
}).catch(err => { data.option = JSON.stringify(data.option)
message.error("添加失败") AddPusher(data).then(res=>{
console.log(err) message.success("添加成功")
}).finally(()=>{ }).catch(err => {
list(false) message.error("添加失败")
closeAddModal() console.log(err)
}).finally(()=>{
list(false)
cleanAddModal()
})
}) })
} }
@ -141,22 +149,19 @@ const columns = [
title: '名称', title: '名称',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
width: 300
}, },
{ {
title: '类型', title: '类型',
dataIndex: 'type', dataIndex: 'type',
key: 'type', key: 'type',
width: 300
}, },
{ {
title: '配置', title: '配置',
dataIndex: 'option', dataIndex: 'option',
key: 'option', key: 'option',
}, },
{
title: '更新时间',
dataIndex: 'updatedAt',
key: 'updatedAt',
},
{ {
title: '备注', title: '备注',
dataIndex: 'remark', dataIndex: 'remark',
@ -171,6 +176,18 @@ const indicator = h(LoadingOutlined, {
spin: true, spin: true,
}); });
const options = ref()
const listOptions = ()=>{
ListPusherOptions().then(res=>{
options.value = res.options
}).catch(err=>{
message.error("获取配置失败")
console.log(err)
})
}
</script> </script>
<style scoped> <style scoped>

View File

@ -29,6 +29,20 @@ export default defineConfig({
secure: false, secure: false,
ws: true, ws: true,
}, },
'/api/v1/push': {
target: 'https://ht-dev.timerzz.com:20443/',
// target: 'http://192.168.31.55:2280/',
changeOrigin: true,
secure: false,
ws: true,
},
'/api/v1/pushers': {
target: 'https://ht-dev.timerzz.com:20443/',
// target: 'http://192.168.31.55:2280/',
changeOrigin: true,
secure: false,
ws: true,
},
'/api/v1': { '/api/v1': {
target: 'https://ht.timerzz.com:20443/', target: 'https://ht.timerzz.com:20443/',
// target: 'http://192.168.31.55:2280/', // target: 'http://192.168.31.55:2280/',