|
@@ -0,0 +1,185 @@
|
|
|
|
+<template>
|
|
|
|
+ <el-dialog :title="state.ruleForm.menuId ? $t('common.editBtn') : $t('common.addBtn')" width="600" v-model="visible"
|
|
|
|
+ :close-on-click-modal="false" :destroy-on-close="true" draggable>
|
|
|
|
+ <el-form ref="menuDialogFormRef" :model="state.ruleForm" :rules="dataRules" label-width="90px" v-loading="loading">
|
|
|
|
+ <el-form-item :label="$t('marketingConfig.name')" prop="domain">
|
|
|
|
+ <el-input v-model="state.ruleForm.domain" clearable :placeholder="$t('marketingConfig.inputNameTip')"></el-input>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item :label="$t('marketingConfig.config')" prop="configs">
|
|
|
|
+ <div v-for="(item, index) in state.ruleForm.configs" :key="item.index" class="config-container">
|
|
|
|
+ <span>IP</span> <el-input style="width: 140px;" v-model="item.ip" clearable :placeholder="$t('marketingConfig.inputIPTip')"></el-input>
|
|
|
|
+ <span>{{ $t('marketingConfig.app') }}</span>
|
|
|
|
+ <el-select style="width: 140px;" v-model="item.appId" clearable :placeholder="$t('marketingConfig.inputAppSel')">
|
|
|
|
+ <el-option v-for="item in state.appList" :key="item.appId" :label="item.appName" :value="item.appId"></el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ <div class="config-actions">
|
|
|
|
+ <svg
|
|
|
|
+ v-if="index === state.ruleForm.configs.length - 1"
|
|
|
|
+ @click="state.ruleForm.configs.push({ ip: '', appId: '', appName: '' })"
|
|
|
|
+ style="cursor: pointer;" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
+ <path d="M19.5 3H4.5C3.67157 3 3 3.67157 3 4.5V19.5C3 20.3284 3.67157 21 4.5 21H19.5C20.3284 21 21 20.3284 21 19.5V4.5C21 3.67157 20.3284 3 19.5 3Z" stroke="#646464" stroke-linejoin="round"/>
|
|
|
|
+ <path d="M12 8V16" stroke="#646464" stroke-linecap="round" stroke-linejoin="round"/>
|
|
|
|
+ <path d="M8 12H16" stroke="#646464" stroke-linecap="round" stroke-linejoin="round"/>
|
|
|
|
+ </svg>
|
|
|
|
+ <svg
|
|
|
|
+ v-if="state.ruleForm.configs.length > 1" style="cursor: pointer;"
|
|
|
|
+ @click="state.ruleForm.configs.splice(index, 1)"
|
|
|
|
+ width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
+ <path d="M19.5 3H4.5C3.67157 3 3 3.67157 3 4.5V19.5C3 20.3284 3.67157 21 4.5 21H19.5C20.3284 21 21 20.3284 21 19.5V4.5C21 3.67157 20.3284 3 19.5 3Z" stroke="#646464" stroke-linejoin="round"/>
|
|
|
|
+ <path d="M8 12H16" stroke="#646464" stroke-linecap="round" stroke-linejoin="round"/>
|
|
|
|
+ </svg>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-form>
|
|
|
|
+ <template #footer>
|
|
|
|
+ <span class="dialog-footer">
|
|
|
|
+ <el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
|
|
|
|
+ <el-button type="primary" @click="onSubmit" :disabled="loading">{{ $t('common.confirmButtonText') }}</el-button>
|
|
|
|
+ </span>
|
|
|
|
+ </template>
|
|
|
|
+ </el-dialog>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script setup lang="ts" name="systemMenuDialog">
|
|
|
|
+import {useI18n} from 'vue-i18n';
|
|
|
|
+import {info, getAppList, save} from '/@/api/marketing/config';
|
|
|
|
+import {useMessage} from '/@/hooks/message';
|
|
|
|
+import {rule} from '/@/utils/validate';
|
|
|
|
+// 定义子组件向父组件传值/事件
|
|
|
|
+const emit = defineEmits(['refresh']);
|
|
|
|
+const {t} = useI18n();
|
|
|
|
+// 引入组件
|
|
|
|
+const IconSelector = defineAsyncComponent(() => import('/@/components/IconSelector/index.vue'));
|
|
|
|
+
|
|
|
|
+// 定义变量内容
|
|
|
|
+const visible = ref(false);
|
|
|
|
+const loading = ref(false);
|
|
|
|
+const menuDialogFormRef = ref();
|
|
|
|
+// 定义需要的数据
|
|
|
|
+const state = reactive({
|
|
|
|
+ ruleForm: {
|
|
|
|
+ id: null,
|
|
|
|
+ domain: '',
|
|
|
|
+ configs: [
|
|
|
|
+ {
|
|
|
|
+ id: '',
|
|
|
|
+ ip: '',
|
|
|
|
+ appId: '',
|
|
|
|
+ appUrl: '',
|
|
|
|
+ appName: ''
|
|
|
|
+ }
|
|
|
|
+ // {
|
|
|
|
+ // id: '1',
|
|
|
|
+ // ip: '美国',
|
|
|
|
+ // appId: '1',
|
|
|
|
+ // appUrl: 'www.baidu.com',
|
|
|
|
+ // appName: 'adsa'
|
|
|
|
+ // },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ appList: [] as any[], // 应用下拉框列表
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// 表单校验规则
|
|
|
|
+const dataRules = reactive({
|
|
|
|
+ domain: [
|
|
|
|
+ {required: true, message: '域名不能为空', trigger: 'blur'},
|
|
|
|
+ { validator: rule.url, trigger: 'blur' }
|
|
|
|
+ ],
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// 打开弹窗
|
|
|
|
+const openDialog = (type: string, row?: any) => {
|
|
|
|
+ visible.value = true;
|
|
|
|
+
|
|
|
|
+ nextTick(() => {
|
|
|
|
+ menuDialogFormRef.value?.resetFields();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (row?.id && type === 'edit') {
|
|
|
|
+ getConfigDetail(row.id);
|
|
|
|
+ } else {
|
|
|
|
+ state.ruleForm = {
|
|
|
|
+ id: null,
|
|
|
|
+ domain: '',
|
|
|
|
+ configs: [
|
|
|
|
+ {
|
|
|
|
+ id: '',
|
|
|
|
+ ip: '',
|
|
|
|
+ appId: '',
|
|
|
|
+ appUrl: '',
|
|
|
|
+ appName: ''
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ // 获取应用列表
|
|
|
|
+ getAllAppData();
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 获取当条配置信息
|
|
|
|
+const getConfigDetail = (id: string) => {
|
|
|
|
+ info(id).then((res) => {
|
|
|
|
+ Object.assign(state.ruleForm, res.data);
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 从后端获取菜单信息(含层级)
|
|
|
|
+const getAllAppData = () => {
|
|
|
|
+ state.appList = [];
|
|
|
|
+ getAppList().then((res) => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ state.appList = res.data;
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 保存数据
|
|
|
|
+const onSubmit = async () => {
|
|
|
|
+ const valid = await menuDialogFormRef.value.validate().catch(() => {
|
|
|
|
+ });
|
|
|
|
+ if (!valid) return false;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ loading.value = true;
|
|
|
|
+ if (!state.ruleForm.id) {
|
|
|
|
+ delete state.ruleForm.id;
|
|
|
|
+ }
|
|
|
|
+ state.ruleForm.configs.forEach((item: any) => {
|
|
|
|
+ item.appName = state.appList.find(app => app.appId === item.appId)?.appName || '';
|
|
|
|
+ item.appUrl = state.appList.find(app => app.appId === item.appId)?.appUrl || '';
|
|
|
|
+ !item.id && delete item.id; // 删除未定义的id
|
|
|
|
+ });
|
|
|
|
+ await save(state.ruleForm);
|
|
|
|
+ useMessage().success(t(state.ruleForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
|
|
|
+ visible.value = false;
|
|
|
|
+ emit('refresh');
|
|
|
|
+ } catch (err: any) {
|
|
|
|
+ useMessage().error(err.msg);
|
|
|
|
+ } finally {
|
|
|
|
+ loading.value = false;
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 暴露变量 只有暴漏出来的变量 父组件才能使用
|
|
|
|
+defineExpose({
|
|
|
|
+ openDialog,
|
|
|
|
+});
|
|
|
|
+</script>
|
|
|
|
+<style scoped>
|
|
|
|
+.config-container {
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+ margin-bottom: 10px;
|
|
|
|
+ font-size: 14px;
|
|
|
|
+ font-weight: 400;
|
|
|
|
+ width: 100%;
|
|
|
|
+ justify-content: space-between;
|
|
|
|
+}
|
|
|
|
+.config-actions {
|
|
|
|
+ width: 50px;
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+ justify-content: space-between;
|
|
|
|
+}
|
|
|
|
+</style>
|