2025-11-22 16:39:01 +08:00
|
|
|
<template>
|
2025-11-24 16:55:18 +08:00
|
|
|
<div class="system-edit-role-container">
|
|
|
|
|
<el-dialog title="" v-model="isShowDialog" width="769px">
|
2025-11-27 15:37:13 +08:00
|
|
|
<el-form ref="formRef" :model="state.formData" :rules="rules" size="default" label-width="90px">
|
2025-11-24 16:55:18 +08:00
|
|
|
<el-row :gutter="35">
|
|
|
|
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
|
|
<el-form-item label="标签" prop="name">
|
2025-11-27 15:37:13 +08:00
|
|
|
<el-input v-model="formData.tag" :placeholder="formData.tag" clearable />
|
2025-11-24 16:55:18 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
2025-11-25 17:02:31 +08:00
|
|
|
<!-- 富文本编辑器 -->
|
2025-11-24 16:55:18 +08:00
|
|
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
|
|
|
<el-form-item label="产品详情" prop="content">
|
2025-11-27 15:37:13 +08:00
|
|
|
<Editor v-model="formData.content" height="400px" :placeholder="formData.content" />
|
2025-11-24 16:55:18 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<span class="dialog-footer">
|
|
|
|
|
<el-button @click="onCancel" size="default">取 消</el-button>
|
2025-11-25 17:02:31 +08:00
|
|
|
<el-button type="primary" @click="onSubmit" size="default" :loading="loading">
|
|
|
|
|
{{ formData.id === 0 ? '新 增' : '修 改' }}
|
|
|
|
|
</el-button>
|
2025-11-24 16:55:18 +08:00
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
2025-11-22 16:39:01 +08:00
|
|
|
</template>
|
|
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { ref, reactive, toRefs, nextTick } from 'vue';
|
|
|
|
|
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
|
2025-11-24 16:55:18 +08:00
|
|
|
import Editor from '/@/components/editor/index.vue';
|
2025-11-27 15:37:13 +08:00
|
|
|
import { getscriptAdd, updatescript } from '/@/api/customerService/script';
|
|
|
|
|
import { Session } from '/@/utils/storage';
|
|
|
|
|
// console.log(Session.get('userInfo').userNickname, 'user');
|
2025-11-22 16:39:01 +08:00
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
// 定义类型接口
|
2025-11-22 16:39:01 +08:00
|
|
|
interface MenuDataTree {
|
2025-11-24 16:55:18 +08:00
|
|
|
id: number;
|
|
|
|
|
pid: number;
|
|
|
|
|
title: string;
|
|
|
|
|
children?: MenuDataTree[];
|
2025-11-22 16:39:01 +08:00
|
|
|
}
|
2025-11-25 17:02:31 +08:00
|
|
|
|
2025-11-22 16:39:01 +08:00
|
|
|
interface DialogRow {
|
2025-11-24 16:55:18 +08:00
|
|
|
id: number;
|
2025-11-27 15:37:13 +08:00
|
|
|
tag: string;
|
|
|
|
|
creator: string;
|
|
|
|
|
content: string;
|
2025-11-22 16:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
// 定义事件
|
|
|
|
|
const emit = defineEmits<{
|
2025-11-27 15:37:13 +08:00
|
|
|
(e: 'success'): void;
|
2025-11-25 17:02:31 +08:00
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
// 响应式数据
|
|
|
|
|
const state = reactive({
|
|
|
|
|
loading: false,
|
|
|
|
|
isShowDialog: false,
|
|
|
|
|
formData: {
|
|
|
|
|
id: 0,
|
2025-11-27 15:37:13 +08:00
|
|
|
tag: '',
|
2025-11-25 17:02:31 +08:00
|
|
|
content: '',
|
2025-11-27 15:37:13 +08:00
|
|
|
creator: '',
|
2025-11-28 17:17:07 +08:00
|
|
|
modifier: '',
|
2025-11-27 15:37:13 +08:00
|
|
|
},
|
2025-11-25 17:02:31 +08:00
|
|
|
menuData: [] as MenuDataTree[],
|
|
|
|
|
menuExpand: false,
|
|
|
|
|
menuNodeAll: false,
|
|
|
|
|
menuCheckStrictly: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 表单验证规则
|
|
|
|
|
const rules: FormRules = {
|
2025-11-27 15:37:13 +08:00
|
|
|
tag: [{ required: true, message: '标签名称不能为空', trigger: 'blur' }],
|
2025-11-25 17:02:31 +08:00
|
|
|
content: [{ required: true, message: '产品详情不能为空', trigger: 'blur' }],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 模板引用
|
|
|
|
|
const formRef = ref<FormInstance>();
|
|
|
|
|
const menuRef = ref();
|
|
|
|
|
|
|
|
|
|
// 解构状态数据
|
|
|
|
|
const { loading, isShowDialog, formData, menuData, menuExpand, menuNodeAll, menuCheckStrictly } = toRefs(state);
|
|
|
|
|
|
|
|
|
|
// 菜单配置
|
|
|
|
|
const menuProps = {
|
|
|
|
|
children: 'children',
|
|
|
|
|
label: 'title',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开对话框
|
|
|
|
|
* @param row - 可选的编辑数据
|
|
|
|
|
*/
|
|
|
|
|
const openDialog = (row?: DialogRow) => {
|
|
|
|
|
resetForm();
|
2025-11-27 15:37:13 +08:00
|
|
|
console.log(row, 'row');
|
2025-11-25 17:02:31 +08:00
|
|
|
if (row) {
|
2025-11-27 15:37:13 +08:00
|
|
|
state.formData = row;
|
2025-11-25 17:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state.isShowDialog = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关闭对话框
|
|
|
|
|
*/
|
|
|
|
|
const closeDialog = () => {
|
|
|
|
|
state.isShowDialog = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取消操作
|
|
|
|
|
*/
|
|
|
|
|
const onCancel = () => {
|
|
|
|
|
closeDialog();
|
|
|
|
|
};
|
2025-11-22 16:39:01 +08:00
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
/**
|
|
|
|
|
* 提交表单
|
|
|
|
|
*/
|
|
|
|
|
const onSubmit = async () => {
|
|
|
|
|
if (!formRef.value) return;
|
2025-11-22 16:39:01 +08:00
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
try {
|
|
|
|
|
// 表单验证
|
|
|
|
|
const valid = await formRef.value.validate();
|
|
|
|
|
if (!valid) return;
|
2025-11-22 16:39:01 +08:00
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
state.loading = true;
|
|
|
|
|
|
|
|
|
|
if (state.formData.id === 0) {
|
2025-11-27 15:37:13 +08:00
|
|
|
state.formData.creator = Session.get('userInfo').userNickname;
|
|
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
// 新增模式
|
2025-11-27 15:37:13 +08:00
|
|
|
await getscriptAdd(state.formData);
|
|
|
|
|
console.log(state.formData);
|
2025-11-25 17:02:31 +08:00
|
|
|
ElMessage.success('添加成功');
|
|
|
|
|
} else {
|
2025-11-27 15:37:13 +08:00
|
|
|
state.formData.modifier = Session.get('userInfo').userNickname;
|
2025-11-25 17:02:31 +08:00
|
|
|
// 编辑模式
|
2025-11-27 15:37:13 +08:00
|
|
|
await updatescript(state.formData);
|
2025-11-25 17:02:31 +08:00
|
|
|
ElMessage.success('修改成功');
|
2025-11-24 16:55:18 +08:00
|
|
|
}
|
2025-11-22 16:39:01 +08:00
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
// 关闭对话框并刷新列表
|
|
|
|
|
closeDialog();
|
2025-11-27 15:37:13 +08:00
|
|
|
emit('success');
|
2025-11-25 17:02:31 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('提交失败:', error);
|
|
|
|
|
ElMessage.error('操作失败');
|
|
|
|
|
} finally {
|
|
|
|
|
state.loading = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重置表单
|
|
|
|
|
*/
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
state.menuCheckStrictly = false;
|
|
|
|
|
state.menuExpand = false;
|
|
|
|
|
state.menuNodeAll = false;
|
|
|
|
|
state.formData = {
|
|
|
|
|
id: 0,
|
2025-11-27 15:37:13 +08:00
|
|
|
tag: '',
|
2025-11-25 17:02:31 +08:00
|
|
|
content: '',
|
2025-11-27 15:37:13 +08:00
|
|
|
creator: '',
|
2025-11-25 17:02:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 重置表单验证状态
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
formRef.value?.clearValidate();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 暴露方法给父组件使用
|
|
|
|
|
defineExpose({
|
|
|
|
|
openDialog,
|
|
|
|
|
closeDialog,
|
2025-11-22 16:39:01 +08:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2025-11-25 17:02:31 +08:00
|
|
|
.system-edit-role-container {
|
|
|
|
|
:deep(.el-dialog__body) {
|
|
|
|
|
padding: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.mb20 {
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dialog-footer {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-22 16:39:01 +08:00
|
|
|
.tree-border {
|
2025-11-24 16:55:18 +08:00
|
|
|
margin-top: 5px;
|
2025-11-25 17:02:31 +08:00
|
|
|
border: 1px solid #e5e6e7;
|
2025-11-24 16:55:18 +08:00
|
|
|
border-radius: 4px;
|
2025-11-22 16:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-25 17:02:31 +08:00
|
|
|
.menu-data-tree {
|
|
|
|
|
border: var(--el-input-border, var(--el-border-base));
|
|
|
|
|
border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
|
|
|
|
|
padding: 5px;
|
2025-11-22 16:39:01 +08:00
|
|
|
}
|
|
|
|
|
</style>
|