wujingjing
2024-11-03 2af68406788a95115dd8312c9cd20e70104cd573
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<template>
    <ywDialog
        v-model="dialogIsShow"
        :headerIcon="dialogHeaderIcon"
        :title="dialogTitle"
        width="470"
        @dlgClosed="closeDialog"
        @submit="submitFormValue"
    >
        <el-form :model="dialogFormValue" ref="dialogFormRef" :rules="dialogFormRules" label-width="76">
            <el-form-item label="标题" prop="title">
                <el-input v-model="dialogFormValue.title"></el-input>
            </el-form-item>
            <el-form-item label="提示词" prop="prompt">
                <el-input v-model="dialogFormValue.prompt" type="textarea" :rows="3"></el-input>
            </el-form-item>
            <el-form-item label="问题" prop="question">
                <el-input v-model="dialogFormValue.question" type="textarea" :rows="3"></el-input>
            </el-form-item>
 
            <el-form-item label="备注" prop="note">
                <el-input v-model="dialogFormValue.note" type="textarea" :rows="3"></el-input>
            </el-form-item>
        </el-form>
    </ywDialog>
</template>
 
<script setup lang="ts">
import ywDialog from '/@/components/dialog/yw-dialog.vue';
 
import type { FormInstance, FormRules } from 'element-plus';
import { ElMessage, TableInstance } from 'element-plus';
 
import { computed, ref, watch } from 'vue';
// import { useTableSort } from '/@/hooks/useTableSort';
// import { useValidateUniqueness } from '/@/hooks/useValidateUniqueness';
import { deepClone } from '/@/utils/other';
 
import { SupervisorPublished, supervisorPublishedMap } from '../types';
import * as supervisorAdminApi from '/@/api/supervisorAdmin';
import JsonEditor from '/@/components/form/jsonEditor/JsonEditor.vue';
import { useCompRef } from '/@/utils/types';
import EditTable from '/@/components/table/editTable/EditTable.vue';
import EditTableColumn from '/@/components/table/editTable/EditTableColumn.vue';
import { formatDate } from '/@/utils/formatTime';
import { useUserInfo } from '/@/stores/userInfo';
import { storeToRefs } from 'pinia';
 
const props = defineProps(['item', 'groupId']);
const emit = defineEmits(['update', 'insert']);
//#region ====================== 增加、修改记录操作, dialog init======================
const isEditDialog = ref(false);
const dialogTitle = computed(() => {
    return isEditDialog.value ? '修改页面' : '添加页面';
});
const dialogHeaderIcon = computed(() => {
    return isEditDialog.value ? 'ele-Edit' : 'ele-Plus';
});
const dialogFormValue = ref(null);
const dialogIsShow = defineModel({
    type: Boolean,
});
const dialogFormRef = ref<FormInstance>(null);
 
const dialogFormRules = ref<FormRules>({
    title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
    prompt: [{ required: true, message: '请输入提示词', trigger: 'blur' }],
});
const openOperateDialog = (row?) => {
    if (row) {
        isEditDialog.value = true;
        const { id, note, prompt, question, title } = row;
        dialogFormValue.value = deepClone({ id, note, prompt, question, title });
    } else {
        isEditDialog.value = false;
 
        dialogFormValue.value = { group: props.groupId, title: null, prompt: null, note: null, question: null };
    }
};
const closeDialog = () => {
    dialogIsShow.value = false;
    dialogFormRef.value.clearValidate();
};
const stores = useUserInfo();
const { userInfos } = storeToRefs(stores);
 
const submitFormValue = async () => {
    const valid = await dialogFormRef.value.validate().catch(() => {});
    if (!valid) return;
 
    const sendForm = { ...dialogFormValue.value };
    const updateTime = formatDate(new Date());
    if (isEditDialog.value) {
        const res = await supervisorAdminApi.updateSupervisor(sendForm);
        emit('update', { ...dialogFormValue.value, update_time: updateTime.slice(0, 10) });
 
        closeDialog();
        ElMessage.success('修改页面成功');
    } else {
        const res = await supervisorAdminApi.addSupervisor(sendForm);
        const newData = {
            id: res.agent_id,
            ...dialogFormValue.value,
            create_time: updateTime.slice(0, 10),
            update_time: updateTime.slice(0, 10),
            creator: userInfos.value.userName,
        };
        emit('insert', newData);
        // tableData.value.push(newData);
        closeDialog();
        ElMessage.success('添加页面成功');
    }
};
 
//#endregion
 
watch(
    () => dialogIsShow.value,
    (val) => {
        if (!val) return;
        openOperateDialog(props.item);
    }
);
</script>
<style scoped lang="scss"></style>