index.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div id="add">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <component :is="partsSearch"></component>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <component :is="CForm" :fields="infoFields" :rules="rules" :form="form" labelWidth="auto" @save="toSave">
  10. <template #is_use>
  11. <el-option v-for="i in isuseList" :key="i.model" :label="i.dict_label" :value="i.dict_value"></el-option>
  12. </template>
  13. <template #content>
  14. <component :is="WangEditor" v-model="form.content" url="/files/studioadmin/other/upload"></component>
  15. </template>
  16. </component>
  17. </el-col>
  18. </el-col>
  19. </el-row>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import partsSearch from '@common/src/components/frame/c-search.vue';
  24. import CForm from '@common/src/components/frame/c-form.vue';
  25. import WangEditor from '@common/src/components/frame/wang-editor.vue';
  26. import store from '@/stores/counter';
  27. import type { Ref } from 'vue';
  28. import { ref, onMounted, reactive } from 'vue';
  29. import type { FormRules } from 'element-plus';
  30. import { ElMessage } from 'element-plus';
  31. import { ContactofficeStore } from '@common/src/stores/studio/other/contactoffice'; // 列表 // 列表
  32. import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
  33. import type { IQueryResult } from '@/util/types.util';
  34. const contactoffice = ContactofficeStore();
  35. const sysdictdata = DictDataStore();
  36. // 表单
  37. let form: Ref<{ content: string }> = ref({ content: '' });
  38. // 必填项
  39. const rules = reactive<FormRules>({
  40. is_use: [{ required: true, message: '请选择是否启用', trigger: 'change' }],
  41. content: [{ required: true, message: '请输入信息内容', trigger: 'blur' }],
  42. });
  43. // 表单
  44. let infoFields: Ref<any[]> = ref([
  45. { label: '是否启用', model: 'is_use', type: 'select' },
  46. { label: '信息内容', model: 'content', custom: true },
  47. ]);
  48. let isuseList: Ref<any[]> = ref([]);
  49. let user = store.state.user as { _id: string; role_type: string };
  50. onMounted(async () => {
  51. await searchOther();
  52. await search();
  53. });
  54. const search = async () => {
  55. const res: IQueryResult = await contactoffice.query();
  56. form.value = res.data[0] as { content: string };
  57. };
  58. // 提交
  59. const toSave = async (data: { _id: string; user_id: string }) => {
  60. data.user_id = user._id;
  61. let res: IQueryResult;
  62. if (data._id) res = await contactoffice.update(data);
  63. else res = await contactoffice.create(data);
  64. if (res.errcode == 0) ElMessage({ type: 'success', message: '维护信息成功' });
  65. else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  66. };
  67. // 查询其他信息
  68. const searchOther = async () => {
  69. // 字典表---审核状态
  70. const p1: IQueryResult = await sysdictdata.query({ dict_type: 'sys_yes_no' });
  71. isuseList.value = p1.data as [];
  72. };
  73. </script>
  74. <style lang="scss" scoped></style>