index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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="/files/material/config/upload"
  15. :list="form[item.model]"
  16. listType="picture-card"
  17. @change="onUpload"
  18. ></cUpload>
  19. </template>
  20. </cForm>
  21. </el-col>
  22. </el-col>
  23. </el-row>
  24. </div>
  25. </template>
  26. <script setup lang="ts">
  27. // 基础
  28. import type { Ref } from 'vue';
  29. import { ref, reactive, onMounted } from 'vue';
  30. import { ElMessage } from 'element-plus';
  31. import type { FormRules } from 'element-plus';
  32. // 接口
  33. import { ConfigStore } from '@/stores/config';
  34. import type { IQueryResult } from '@/util/types.util';
  35. const configAxios = ConfigStore();
  36. // 加载中
  37. const loading: Ref<any> = ref(false);
  38. // 表单
  39. let form: Ref<any> = ref({});
  40. let fields: Ref<any[]> = ref([{ label: 'logo', model: 'logo_url', custom: true }]);
  41. const rules = reactive<FormRules>({});
  42. // 请求
  43. onMounted(async () => {
  44. loading.value = true;
  45. await search();
  46. loading.value = false;
  47. });
  48. const search = async () => {
  49. let res: IQueryResult = await configAxios.query();
  50. if (res.errcode == '0') {
  51. form.value = res.data;
  52. }
  53. };
  54. const onUpload = (e: { model: string; value: Array<[]> }) => {
  55. const { model, value } = e;
  56. form.value[model] = value;
  57. };
  58. const toSave = async (data) => {
  59. let res: IQueryResult;
  60. if (data._id) res = await configAxios.update(data);
  61. else res = await configAxios.create(data);
  62. if (res.errcode == 0) {
  63. ElMessage({ type: `success`, message: `维护信息成功` });
  64. search();
  65. }
  66. };
  67. </script>
  68. <style scoped lang="scss"></style>