index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false"></cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cForm :span="24" :fields="fields" :form="form" :rules="rules" @save="toSave" label-width="auto">
  10. <template #logo_url="{ item }">
  11. <cUpload
  12. :model="item.model"
  13. :limit="1"
  14. url="/visit/api/files/config/upload"
  15. :list="form[item.model]"
  16. listType="picture-card"
  17. @change="onUpload"
  18. ></cUpload>
  19. </template>
  20. <template #group_url="{ item }">
  21. <cUpload
  22. :model="item.model"
  23. :limit="1"
  24. url="/visit/api/files/config/upload"
  25. :list="form[item.model]"
  26. listType="picture-card"
  27. @change="onUpload"
  28. ></cUpload>
  29. </template>
  30. <template #friend_url="{ item }">
  31. <cUpload
  32. :model="item.model"
  33. :limit="1"
  34. url="/visit/api/files/config/upload"
  35. :list="form[item.model]"
  36. listType="picture-card"
  37. @change="onUpload"
  38. ></cUpload>
  39. </template>
  40. <template #user_url="{ item }">
  41. <cUpload
  42. :model="item.model"
  43. :limit="1"
  44. url="/visit/api/files/config/upload"
  45. :list="form[item.model]"
  46. listType="picture-card"
  47. @change="onUpload"
  48. ></cUpload>
  49. </template>
  50. <template #agreement>
  51. <cEditor v-model="form.agreement" url="/visit/api/files/config/upload"></cEditor>
  52. </template>
  53. </cForm>
  54. </el-col>
  55. </el-col>
  56. </el-row>
  57. </div>
  58. </template>
  59. <script setup lang="ts">
  60. // 基础
  61. import type { Ref } from 'vue';
  62. import { ref, reactive, onMounted } from 'vue';
  63. import { ElMessage } from 'element-plus';
  64. import type { FormRules } from 'element-plus';
  65. // 接口
  66. import { ConfigStore } from '@/stores/basic/config';
  67. import type { IQueryResult } from '@/util/types.util';
  68. const configAxios = ConfigStore();
  69. // 加载中
  70. const loading: Ref<any> = ref(false);
  71. // 表单
  72. let form: Ref<any> = ref({});
  73. let fields: Ref<any[]> = ref([
  74. { label: 'logo', model: 'logo_url', custom: true },
  75. { label: '群组logo', model: 'group_url', custom: true },
  76. { label: '好友logo', model: 'friend_url', custom: true },
  77. { label: '用户默认头像', model: 'user_url', custom: true },
  78. { label: '用户协议和隐私协议', model: 'agreement', custom: true },
  79. { label: '底部文案', model: 'bottom_title' }
  80. ]);
  81. const rules = reactive<FormRules>({});
  82. // 请求
  83. onMounted(async () => {
  84. loading.value = true;
  85. await search();
  86. loading.value = false;
  87. });
  88. const search = async () => {
  89. let res: IQueryResult = await configAxios.query();
  90. if (res.errcode == '0') {
  91. form.value = res.data;
  92. }
  93. };
  94. const onUpload = (e: { model: string; value: Array<[]> }) => {
  95. const { model, value } = e;
  96. form.value[model] = value;
  97. };
  98. const toSave = async (data) => {
  99. let res: IQueryResult;
  100. if (data._id) res = await configAxios.update(data);
  101. else res = await configAxios.create(data);
  102. if (res.errcode == 0) {
  103. ElMessage({ type: `success`, message: `维护信息成功` });
  104. search();
  105. }
  106. };
  107. </script>
  108. <style scoped lang="scss"></style>