drag-create-back/src/pages/index/code/code_module/components/EditCodeModuleDialog.vue
2023-07-20 21:02:57 +08:00

185 lines
5.3 KiB
Vue

<template>
<el-dialog v-model="props.modelValue" title="编辑代码块" width="900px" @closed="closeDialog" @open="openDialog">
<el-form ref="formRef" :model="formData" :rules="rules">
<el-row>
<el-col :span="12">
<el-form-item :label-width="labelWidth" label="类目" prop="code_module_category_guid">
<el-cascader class="w100" filterable :options="dataList"
:props="{ checkStrictly: false, value: 'code_module_category_guid', label: 'code_module_category_name', emitPath: false }"
placeholder="请选择类目" clearable v-model="formData.code_module_category_guid">
<template #default="{ node, data }">
<span>{{ data.code_module_category_name }}</span>
<span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
</template>
</el-cascader>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label-width="labelWidth" label="代码块名称" prop="code_module_name">
<el-input v-model='formData.code_module_name' type="text" placeholder='请输入代码块名称'></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item :label-width="labelWidth" label="html内容" prop="code_module_html">
<el-input v-model='formData.code_module_html' type="textarea" :rows="5" placeholder='请输入html内容'></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item :label-width="labelWidth" label="style内容" prop="code_module_style">
<el-input v-model='formData.code_module_style' type="textarea" :rows="5" placeholder='请输入style内容'></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item :label-width="labelWidth" label="script内容" prop="code_module_script">
<el-input v-model='formData.code_module_script' type="textarea" :rows="5"
placeholder='请输入script内容'></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label-width="labelWidth" label="排序" prop="code_module_sort">
<el-input-number v-model='formData.code_module_sort' controls-position='right' :min='0'></el-input-number>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="审核状态" prop="code_module_audit">
<el-select v-model="formData.code_module_audit" clearable placeholder="请选择">
<el-option v-for="item in audit_status" :key="item.dictionary_guid" :label="item.dictionary_name"
:value="item.dictionary_value"></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="handleEditClick(formRef)" :loading="isBtnLod">编辑</el-button>
<el-button @click="handleResetClick(formRef)">重置</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup>
import { reactive, ref, watch } from "vue";
import { editCodeModule, getDictionary } from "~/service/code_module";
import { getCodeModuleCategoryList } from "~/service/code_module_category";
import { useLoginStore } from "~/store";
// --业务参数
// --业务方法
// 字典获取
const audit_status = ref([]);
async function get_audit_status() {
await getDictionary({ dictionary_value: 'audit_status' }).then((res) => {
audit_status.value = res
})
}
//获取代码块类目树形列表
const dataList = ref([])
async function getList() {
await getCodeModuleCategoryList({ 'all': true }).then((res) => {
if (res.code == 0) {
dataList.value = res.data
}
})
}
// --基础参数
const store = useLoginStore();
const headers = {
Accept: "application/json",
...store.headers,
};
const isBtnLod = ref(false);
const formRef = ref();
const labelWidth = 100;
const props = defineProps({
modelValue: Boolean,
data: Object,
done: Function,
});
const emits = defineEmits(["update:modelValue"]);
const formData = ref({
...props.data,
});
const uoloadData = ref({
dirName: "CodeModule"
})
// --基础方法
watch(props, (v) => {
formData.value = v.data;
});
// 打开弹窗时执行
const openDialog = async () => {
await get_audit_status()
await getList()
};
const closeDialog = () => {
props.done();
emits("update:modelValue", false);
};
const rules = reactive({
code_module_category_guid: [
{
required: true,
message: '代码库类目不能为空'
}
],
code_module_name: [
{
required: true,
message: '代码块名称不能为空'
}
],
code_module_html: [
{
required: true,
message: 'html内容不能为空'
}
],
});
const handleEditClick = async (formEl) => {
console.log(formData.value);
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) {
return;
}
isBtnLod.value = true;
const { code } = await editCodeModule(formData.value);
if (code == 0) {
closeDialog();
props.done();
}
isBtnLod.value = false;
});
};
const handleResetClick = async (formEl) => {
if (!formEl) return;
formEl.resetFields();
};
</script>
<style lang="less" scoped></style>