zs 1 рік тому
батько
коміт
d9f28312ee

+ 6 - 17
src/components/frame/c-upload.vue

@@ -1,18 +1,8 @@
 <template>
   <div id="c-upload">
-    <el-upload
-      v-if="url"
-      ref="upload"
-      :action="url"
-      :limit="limit"
-      :accept="accept"
-      :file-list="list"
-      :list-type="listType"
-      :on-exceed="outLimit"
-      :on-preview="filePreview"
-      :on-success="onSuccess"
-      :before-remove="onRemove"
-    >
+    <el-upload v-if="url" ref="upload" :action="url" :limit="limit" :accept="accept" :file-list="list"
+      :list-type="listType" :on-exceed="outLimit" :on-preview="filePreview" :on-success="onSuccess"
+      :before-remove="onRemove">
       <el-button type="primary">选择文件</el-button>
       <template #tip v-if="tip">
         <p style="color: #ff0000">{{ tip }}</p>
@@ -75,17 +65,16 @@ const outLimit = () => {
   ElMessage.error(`只允许上传${limit.value}个文件`);
 };
 // 上传成功,response:成功信息,file:图片信息,fileList:图片列表
-const onSuccess = (response: { errcode: string | number; errmsg: string; data: { uri: any } }, file: { name: string }) => {
+const onSuccess = (response: { errcode: string | number; errmsg: string; uri: string }) => {
   if (response.errcode !== 0) {
     ElMessage({ type: 'error', message: '删除成功' });
     return;
   }
-  let ponse = _.omit(response, ['errcode', 'errmsg']);
   let arr: Ref<ListItem[]> = _.cloneDeep(list);
   if (_.isArray(list.value)) {
-    arr.value.push({ ...ponse.data, name: file.name, url: `${import.meta.env.VITE_APP_HOST}${response.data.uri}` });
+    arr.value.push({ ...response, url: `${import.meta.env.VITE_APP_HOST}${response.uri}` });
   } else {
-    arr.value = [{ ...ponse.data, name: file.name, url: `${import.meta.env.VITE_APP_HOST}${response.data.uri}` }];
+    arr.value = [{ ...response, url: `${import.meta.env.VITE_APP_HOST}${response.uri}` }];
   }
   emit('change', { model: model.value, value: arr.value });
 };

+ 5 - 0
src/router/index.ts

@@ -65,6 +65,11 @@ const router = createRouter({
           meta: { title: '景区基本信息' },
           component: () => import('@/views/config/info/index.vue')
         },
+        {
+          path: '/config/module',
+          meta: { title: '首页模块处理' },
+          component: () => import('@/views/config/module/index.vue')
+        },
         {
           path: '/user/user',
           meta: { title: '普通用户' },

+ 52 - 0
src/stores/basic/config.ts

@@ -0,0 +1,52 @@
+import { ref, computed } from 'vue';
+import { defineStore } from 'pinia';
+import { AxiosWrapper } from '@/util/axios-wrapper';
+import _ from 'lodash';
+
+import type { IQueryType, IQueryResult, IQueryParams } from '@/util/types.util';
+const axios = new AxiosWrapper();
+const api = {
+  url: `/travel/v1/api/config`
+};
+export const ConfigStore = defineStore('config', () => {
+  const count = ref(0);
+  const doubleCount = computed(() => count.value * 2);
+  function increment() {
+    count.value++;
+  }
+  const query = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
+    let cond: IQueryType = {};
+    if (skip) cond.skip = skip;
+    if (limit) cond.limit = limit;
+    cond = { ...cond, ...info };
+    const res = await axios.$get(`${api.url}`, cond);
+    return res;
+  };
+  const fetch = async (payload: any): Promise<IQueryResult> => {
+    const res = await axios.$get(`${api.url}/${payload}`);
+    return res;
+  };
+  const create = async (payload: any): Promise<IQueryResult> => {
+    const res = await axios.$post(`${api.url}`, payload);
+    return res;
+  };
+  const update = async (payload: any): Promise<IQueryResult> => {
+    const id = _.get(payload, 'id', _.get(payload, '_id'));
+    const res = await axios.$post(`${api.url}/${id}`, payload);
+    return res;
+  };
+  const del = async (payload: any): Promise<IQueryResult> => {
+    const res = await axios.$delete(`${api.url}/${payload}`);
+    return res;
+  };
+  return {
+    count,
+    doubleCount,
+    increment,
+    query,
+    fetch,
+    create,
+    update,
+    del
+  };
+});

+ 52 - 0
src/stores/basic/module.ts

@@ -0,0 +1,52 @@
+import { ref, computed } from 'vue';
+import { defineStore } from 'pinia';
+import { AxiosWrapper } from '@/util/axios-wrapper';
+import _ from 'lodash';
+
+import type { IQueryType, IQueryResult, IQueryParams } from '@/util/types.util';
+const axios = new AxiosWrapper();
+const api = {
+  url: `/travel/v1/api/module`
+};
+export const ModuleStore = defineStore('module', () => {
+  const count = ref(0);
+  const doubleCount = computed(() => count.value * 2);
+  function increment() {
+    count.value++;
+  }
+  const query = async ({ skip = 0, limit = undefined, ...info }: IQueryParams = {}): Promise<IQueryResult> => {
+    let cond: IQueryType = {};
+    if (skip) cond.skip = skip;
+    if (limit) cond.limit = limit;
+    cond = { ...cond, ...info };
+    const res = await axios.$get(`${api.url}`, cond);
+    return res;
+  };
+  const fetch = async (payload: any): Promise<IQueryResult> => {
+    const res = await axios.$get(`${api.url}/${payload}`);
+    return res;
+  };
+  const create = async (payload: any): Promise<IQueryResult> => {
+    const res = await axios.$post(`${api.url}`, payload);
+    return res;
+  };
+  const update = async (payload: any): Promise<IQueryResult> => {
+    const id = _.get(payload, 'id', _.get(payload, '_id'));
+    const res = await axios.$post(`${api.url}/${id}`, payload);
+    return res;
+  };
+  const del = async (payload: any): Promise<IQueryResult> => {
+    const res = await axios.$delete(`${api.url}/${payload}`);
+    return res;
+  };
+  return {
+    count,
+    doubleCount,
+    increment,
+    query,
+    fetch,
+    create,
+    update,
+    del
+  };
+});

+ 81 - 18
src/views/config/info/index.vue

@@ -2,7 +2,32 @@
   <div id="index">
     <el-row>
       <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
-        <el-col :span="24" class="one"> 系统首页 </el-col>
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false"></cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cForm :span="24" :fields="fields" :form="form" :rules="rules" @save="toSave" label-width="auto">
+            <template #brief>
+              <cEditor v-model="form.brief" url="/file/travel/config/upload"></cEditor>
+            </template>
+            <template #file="{ item }">
+              <cUpload
+                :model="item.model"
+                :limit="6"
+                url="/files/travel/config/upload"
+                :list="form[item.model]"
+                listType="picture-card"
+                @change="onUpload"
+              ></cUpload>
+            </template>
+            <template #video="{ item }">
+              <cUpload :model="item.model" :limit="6" url="/files/travel/config/upload" :list="form[item.model]" @change="onUpload"></cUpload>
+            </template>
+            <template #status>
+              <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
+            </template>
+          </cForm>
+        </el-col>
       </el-col>
     </el-row>
   </div>
@@ -11,31 +36,69 @@
 <script setup lang="ts">
 // 基础
 import type { Ref } from 'vue';
-import { onMounted, ref } from 'vue';
-
+import { ref, reactive, onMounted } from 'vue';
+import { ElMessage } from 'element-plus';
+import type { FormRules } from 'element-plus';
 // 接口
-// import { ToolsStore } from '@/stores/tool';
-// import type { IQueryResult } from '@/util/types.util';
-// const toolsAxios = ToolsStore();
-
+import { ConfigStore } from '@/stores/basic/config';
+import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const configAxios = ConfigStore();
+const dictAxios = DictDataStore();
 // 加载中
 const loading: Ref<any> = ref(false);
-
+// 表单
+let form: Ref<any> = ref({ file: [], video: [] });
+let fields: Ref<any[]> = ref([
+  { label: '景区名称', model: 'name' },
+  { label: '景区联系电话', model: 'phone' },
+  { label: '景区地址', model: 'address' },
+  { label: '开放时间', model: 'open_time' },
+  { label: '优待政策', model: 'policy', type: 'textarea' },
+  { label: '用户协议', model: 'agreement', type: 'textarea' },
+  { label: '隐私政策', model: 'secret', type: 'textarea' },
+  { label: '简介', model: 'brief', custom: true },
+  { label: '图片', model: 'file', custom: true },
+  { label: '视频', model: 'video', custom: true },
+  { label: '底部文案', model: 'bottom_title' },
+  { label: '状态', model: 'status', type: 'select' }
+]);
+const rules = reactive<FormRules>({});
+// 字典表
+const statusList: Ref<any> = ref([]);
 // 请求
 onMounted(async () => {
   loading.value = true;
-  search();
+  await searchOther();
+  await search();
   loading.value = false;
 });
 const search = async () => {
-  // let res: IQueryResult = await toolsAxios.dataCount();
-  // if (res.errcode == '0') {
-  //   info.value = res.data;
-  // }
+  let res: IQueryResult = await configAxios.query();
+  if (res.errcode == '0') {
+    form.value = res.data;
+  }
+};
+const onUpload = (e: { model: string; value: Array<[]> }) => {
+  const { model, value } = e;
+  form.value[model] = value;
+};
+const toSave = async (data: any) => {
+  let res: IQueryResult;
+  console.log(data);
+  if (data._id) res = await configAxios.update(data);
+  else res = await configAxios.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    search();
+  }
+};
+// 查询其他信息
+const searchOther = async () => {
+  let res: IQueryResult;
+  // 状态
+  res = await dictAxios.query({ type: 'config_status', is_use: '0' });
+  if (res.errcode == '0') statusList.value = res.data;
 };
 </script>
-<style scoped lang="scss">
-.main {
-  padding: 2px;
-}
-</style>
+<style scoped lang="scss"></style>

+ 195 - 0
src/views/config/module/index.vue

@@ -0,0 +1,195 @@
+<template>
+  <div id="index">
+    <el-row>
+      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
+        <el-col :span="24" class="one">
+          <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch"> </cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cButton @toAdd="toAdd()"> </cButton>
+        </el-col>
+        <el-col :span="24" class="thr">
+          <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel">
+            <template #is_use="{ row }">
+              <el-switch
+                v-model="row.is_use"
+                inline-prompt
+                active-text="是"
+                inactive-text="否"
+                active-value="0"
+                inactive-value="1"
+                @click="handleChange(row)"
+              ></el-switch>
+            </template>
+          </cTable>
+        </el-col>
+      </el-col>
+    </el-row>
+    <cDialog :dialog="dialog" @toClose="toClose">
+      <template v-slot:info>
+        <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
+          <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="toSave" label-width="auto">
+            <template #url>
+              <cUpload
+                :model="`${'url'}`"
+                :limit="1"
+                listType="picture-card"
+                url="/files/travel/module/upload"
+                accept="*"
+                :list="form.url"
+                @change="onUpload"
+              ></cUpload>
+            </template>
+            <template #is_use>
+              <el-radio v-for="i in is_useList" :key="i._id" :label="i.value">{{ i.label }}</el-radio>
+            </template>
+          </cForm>
+        </el-col>
+      </template>
+    </cDialog>
+  </div>
+</template>
+
+<script setup lang="ts">
+// 基础
+import type { FormRules } from 'element-plus';
+import type { Ref } from 'vue';
+import { ref, onMounted, getCurrentInstance, reactive } from 'vue';
+import { ElMessage, ElMessageBox } from 'element-plus';
+// 接口
+import { ModuleStore } from '@/stores/basic/module';
+import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const moduleAxios = ModuleStore();
+const dictAxios = DictDataStore();
+const { proxy } = getCurrentInstance() as any;
+// 加载中
+const loading: Ref<any> = ref(false);
+let list: Ref<any> = ref([]);
+let total: Ref<number> = ref(0);
+let skip = 0;
+let limit: number = proxy.$limit;
+let fields: Ref<any[]> = ref([
+  { label: '名称', model: 'name', isSearch: true },
+  { label: '路由', model: 'route' },
+  { label: '排序', model: 'sort', type: 'number' },
+  { label: '是否使用', model: 'is_use', custom: true }
+]);
+// 操作
+let opera: Ref<any[]> = ref([
+  { label: '修改', method: 'edit' },
+  { label: '删除', method: 'del', confirm: true, type: 'danger' }
+]);
+// 查询数据
+let searchForm: Ref<any> = ref({});
+// 字典表
+let is_useList: Ref<any> = ref([]);
+// 弹框
+const dialog: Ref<any> = ref({ title: '信息管理', show: false, type: '1' });
+const form: Ref<any> = ref({ url: [] });
+const formFields: Ref<any> = ref([
+  { label: '名称', model: 'name' },
+  { label: '路由', model: 'route' },
+  { label: '排序', model: 'sort', type: 'number' },
+  { label: '图片', model: 'url', custom: true },
+  { label: '是否使用', model: 'is_use', type: 'radio' }
+]);
+const rules = reactive<FormRules>({
+  name: [{ required: true, message: '名称', trigger: 'blur' }],
+  route: [{ required: true, message: '路由', trigger: 'blur' }],
+  url: [{ required: true, message: '图片', trigger: 'blur' }],
+  sort: [{ required: true, message: '排序', trigger: 'blur' }]
+});
+// 请求
+onMounted(async () => {
+  loading.value = true;
+  await searchOther();
+  await search({ skip, limit });
+  loading.value = false;
+});
+const search = async (e: { skip: number; limit: number }) => {
+  const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
+  const res: IQueryResult = await moduleAxios.query(info);
+  if (res.errcode == '0') {
+    list.value = res.data;
+    total.value = res.total;
+  }
+};
+const toSearch = (query: any) => {
+  searchForm.value = query;
+  search({ skip, limit });
+};
+const onUpload = (e: { model: string; value: Array<[]> }) => {
+  const { model, value } = e;
+  form.value[model] = value;
+};
+// 提交保存
+const toSave = async (data: any) => {
+  let res: IQueryResult;
+  if (data._id) res = await moduleAxios.update(data);
+  else res = await moduleAxios.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    toClose();
+  }
+};
+// 新增
+const toAdd = () => {
+  dialog.value = { title: '信息管理', show: true, type: '1' };
+};
+// 修改
+const toEdit = async (data: any) => {
+  let res: IQueryResult = await moduleAxios.fetch(data._id);
+  if (res.errcode == '0') {
+    form.value = res.data;
+    dialog.value = { title: '信息管理', show: true, type: '1' };
+  }
+};
+// 删除
+const toDel = async (data: any) => {
+  let res: IQueryResult = await moduleAxios.del(data._id);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `刪除信息成功` });
+    search({ skip, limit });
+  }
+};
+
+// 关闭弹框
+const toClose = () => {
+  form.value = { url: [] };
+  dialog.value = { show: false };
+  search({ skip, limit });
+};
+
+// 查询其他信息
+const searchOther = async () => {
+  let res: IQueryResult = await dictAxios.query({ type: 'is_use', is_use: '0' });
+  if (res.errcode == 0) is_useList.value = res.data;
+};
+// 修改是否启用
+const handleChange = (row: any) => {
+  const text = row.is_use === '0' ? '启用' : '停用';
+  ElMessageBox.confirm('确认要"' + text + '""' + row.name + '"吗?', '提示', {
+    confirmButtonText: '确定',
+    cancelButtonText: '取消',
+    type: 'warning'
+  })
+    .then(async () => {
+      let res: IQueryResult;
+      if (row._id) res = await moduleAxios.update(row);
+      if (res.errcode == 0) {
+        ElMessage({ type: `success`, message: `修改成功` });
+      }
+    })
+    .catch(() => {
+      row.is_use = row.is_use === '0' ? '1' : '0';
+    });
+};
+</script>
+<style scoped lang="scss">
+.main {
+  .two {
+    margin: 0 0 10px 0;
+  }
+}
+</style>