소스 검색

评论管理

zs 1 년 전
부모
커밋
9d078e6180
5개의 변경된 파일369개의 추가작업 그리고 84개의 파일을 삭제
  1. 5 0
      src/router/index.ts
  2. 57 0
      src/stores/info/comment.ts
  3. 179 14
      src/views/basic/comment/index.vue
  4. 119 0
      src/views/content/article/detail.vue
  5. 9 70
      src/views/content/article/index.vue

+ 5 - 0
src/router/index.ts

@@ -100,6 +100,11 @@ const router = createRouter({
           meta: { title: '游玩攻略管理' },
           component: () => import('@/views/content/article/index.vue')
         },
+        {
+          path: '/content/article/detail',
+          meta: { title: '游玩攻略信息管理' },
+          component: () => import('@/views/content/article/detail.vue')
+        },
         {
           path: '/content/notice',
           meta: { title: '公告管理' },

+ 57 - 0
src/stores/info/comment.ts

@@ -0,0 +1,57 @@
+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/comment`
+};
+export const CommentStore = defineStore('comment', () => {
+  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;
+  };
+  const exam = async (): Promise<IQueryResult> => {
+    const res = await axios.$get(`${api.url}/exam`);
+    return res;
+  };
+  return {
+    count,
+    doubleCount,
+    increment,
+    query,
+    fetch,
+    create,
+    update,
+    del,
+    exam
+  };
+});

+ 179 - 14
src/views/basic/comment/index.vue

@@ -2,40 +2,205 @@
   <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" :is_search="true" :fields="fields" @search="toSearch"></cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <el-button type="primary" @click="toApprove">一键审核通过</el-button>
+        </el-col>
+        <el-col :span="24" class="thr">
+          <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @exam="toExam" @del="toDel">
+            <template #source_name="{ item, row }">
+              <template v-if="item.model === 'source_name'">
+                <el-link size="small" type="primary" @click="toSource(row)">{{ row.source_name }}</el-link>
+              </template>
+            </template>
+            <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="{}" @save="toSave" label-width="auto">
+            <template #status>
+              <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
+            </template>
+          </cForm>
+        </el-col>
+      </template>
+    </cDialog>
   </div>
 </template>
 
 <script setup lang="ts">
 // 基础
+import store from '@/stores/counter';
 import type { Ref } from 'vue';
-import { onMounted, ref } from 'vue';
-
+import { ref, onMounted, getCurrentInstance } from 'vue';
+import { ElMessage, ElMessageBox } from 'element-plus';
+import { useRouter } from 'vue-router';
 // 接口
-// import { ToolsStore } from '@/stores/tool';
-// import type { IQueryResult } from '@/util/types.util';
-// const toolsAxios = ToolsStore();
-
+import { CommentStore } from '@/stores/info/comment';
+import { ArticleStore } from '@/stores/content/article';
+import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const commentAxios = CommentStore();
+const articleAxios = ArticleStore();
+const dictAxios = DictDataStore();
+const { proxy } = getCurrentInstance() as any;
+let user: Ref<any> = ref(store.state.user);
+// 路由
+const router = useRouter();
 // 加载中
 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: 'user_name', isSearch: true },
+  { label: '来源', model: 'source_name', custom: true },
+  { label: '内容', model: 'content' },
+  { label: '创建时间', model: 'create_time' },
+  { label: '是否启用', model: 'is_use', custom: true }
+]);
+// 操作
+let opera: Ref<any[]> = ref([
+  { label: '审核', method: 'exam', type: 'warning', display: (i: any) => i.status == '0' && user.value.type == '0' },
+  { label: '删除', method: 'del', confirm: true, type: 'danger' }
+]);
+// 查询数据
+let searchForm: Ref<any> = ref({});
+// 字典表
+let is_useList: Ref<any> = ref([]);
+let statusList: Ref<any> = ref([]);
 
+// 弹框
+const dialog: Ref<any> = ref({ title: '信息管理', show: false, type: '1' });
+const form: Ref<any> = ref({ file: [] });
+const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
 // 请求
 onMounted(async () => {
   loading.value = true;
-  search();
+  await searchOther();
+  await search({ skip, limit });
   loading.value = false;
 });
-const search = async () => {
-  // let res: IQueryResult = await toolsAxios.dataCount();
-  // if (res.errcode == '0') {
-  //   info.value = res.data;
-  // }
+const search = async (e: { skip: number; limit: number }) => {
+  const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
+  const res: any = await commentAxios.query(info);
+  if (res.errcode == '0') {
+    for (const val of res.data) {
+      const source: any = await articleAxios.fetch(val.source);
+      if (source.errcode == '0') if (source.data) val.source_name = source.data.title;
+    }
+    list.value = res.data;
+    total.value = res.total;
+  }
+};
+const toSearch = (query: any) => {
+  searchForm.value = query;
+  search({ skip, limit });
+};
+// 字典类型跳转
+const toSource = (data: any) => {
+  router.push({ path: '/content/article/detail', query: { id: data.source } });
+};
+// 一键通过
+const toApprove = async () => {
+  ElMessageBox.confirm('确认要一键通过审核吗?', '提示', {
+    confirmButtonText: '确定',
+    cancelButtonText: '取消',
+    type: 'warning'
+  })
+    .then(async () => {
+      let res: IQueryResult = await commentAxios.exam();
+      if (res.errcode == '0') {
+        ElMessage({ type: `success`, message: `审核成功` });
+        search({ skip, limit });
+      }
+    })
+    .catch(() => {});
+};
+// 审核
+const toExam = async (data: any) => {
+  let res: IQueryResult = await commentAxios.fetch(data._id);
+  if (res.errcode == '0') {
+    form.value = res.data;
+    dialog.value = { title: '审核管理', show: true, type: '1' };
+  }
+};
+// 提交保存
+const toSave = async (data: any) => {
+  let res: IQueryResult;
+  if (data._id) res = await commentAxios.update(data);
+  else res = await commentAxios.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    toClose();
+  }
+};
+// 删除
+const toDel = async (data: any) => {
+  let res: IQueryResult = await commentAxios.del(data._id);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `刪除信息成功` });
+    search({ skip, limit });
+  }
+};
+
+// 关闭弹框
+const toClose = () => {
+  form.value = { file: [] };
+  dialog.value = { show: false };
+  search({ skip, limit });
+};
+
+// 查询其他信息
+const searchOther = async () => {
+  let res: IQueryResult;
+  res = await dictAxios.query({ type: 'is_use', is_use: '0' });
+  if (res.errcode == 0) is_useList.value = res.data;
+  // 状态
+  res = await dictAxios.query({ type: 'exam_status', is_use: '0' });
+  if (res.errcode == '0') statusList.value = res.data;
+};
+// 修改是否启用
+const handleChange = (row: any) => {
+  const text = row.is_use === '0' ? '启用' : '停用';
+  ElMessageBox.confirm('确认要"' + text + '""' + row.title + '"吗?', '提示', {
+    confirmButtonText: '确定',
+    cancelButtonText: '取消',
+    type: 'warning'
+  })
+    .then(async () => {
+      let res: IQueryResult;
+      if (row._id) res = await commentAxios.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 {
-  padding: 2px;
+  .two {
+    margin: 0 0 10px 0;
+  }
 }
 </style>

+ 119 - 0
src/views/content/article/detail.vue

@@ -0,0 +1,119 @@
+<template>
+  <div id="detail">
+    <el-row>
+      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
+        <el-col :span="24" class="one">
+          <cSearch :is_back="true" @toBack="toBack"></cSearch>
+        </el-col>
+        <el-col :span="24" class="two">
+          <cForm :span="24" :fields="fields" :form="form" :rules="rules" @save="toSave" label-width="auto">
+            <template #file>
+              <cUpload
+                :model="`${'file'}`"
+                :limit="6"
+                listType="picture-card"
+                url="/files/travel/article/upload"
+                accept="*"
+                :list="form.file"
+                @change="onUpload"
+              ></cUpload>
+            </template>
+            <template #type>
+              <el-option v-for="i in typeList" :key="i.value" :label="i.label" :value="i.value"></el-option>
+            </template>
+            <template #content>
+              <cEditor v-model="form.content" url="/file/travel/article/upload"></cEditor>
+            </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>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script setup lang="ts">
+// 基础
+import type { Ref } from 'vue';
+import { ref, reactive, onMounted } from 'vue';
+import { ElMessage } from 'element-plus';
+import type { FormRules } from 'element-plus';
+import { useRoute } from 'vue-router';
+// 接口
+import { ArticleStore } from '@/stores/content/article';
+import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
+import type { IQueryResult } from '@/util/types.util';
+const articleAxios = ArticleStore();
+const dictAxios = DictDataStore();
+// 路由
+const route = useRoute();
+// 加载中
+const loading: Ref<any> = ref(false);
+// 表单
+let form: Ref<any> = ref({});
+let fields: Ref<any[]> = ref([
+  { label: '标题', model: 'title' },
+  { label: '类型', model: 'type', type: 'select' },
+  { label: '创建时间', model: 'create_time', type: 'datetime' },
+  { label: '排序', model: 'sort', type: 'number' },
+  { label: '图片', model: 'file', custom: true },
+  { label: '内容', model: 'content', custom: true },
+  { label: '是否启用', model: 'is_use', type: 'radio' }
+]);
+const rules = reactive<FormRules>({
+  title: [{ required: true, message: '标题', trigger: 'blur' }],
+  content: [{ required: true, message: '内容', trigger: 'blur' }],
+  type: [{ required: true, message: '类型', trigger: 'blur' }],
+  file: [{ required: true, message: '图片', trigger: 'blur' }],
+  create_time: [{ required: true, message: '创建时间', trigger: 'blur' }],
+  sort: [{ required: true, message: '排序', trigger: 'blur' }]
+});
+// 字典表
+// 字典表
+let is_useList: Ref<any> = ref([]);
+let typeList: Ref<any> = ref([]);
+// 请求
+onMounted(async () => {
+  loading.value = true;
+  await searchOther();
+  await search();
+  loading.value = false;
+});
+const search = async () => {
+  let id = route.query.id;
+  if (id) {
+    let res: IQueryResult = await articleAxios.fetch(id);
+    if (res.errcode == '0') form.value = res.data as {};
+  }
+};
+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 articleAxios.update(data);
+  else res = await articleAxios.create(data);
+  if (res.errcode == 0) {
+    ElMessage({ type: `success`, message: `维护信息成功` });
+    toBack();
+  }
+};
+// 查询其他信息
+const searchOther = async () => {
+  let res: IQueryResult;
+  res = await dictAxios.query({ type: 'is_use', is_use: '0' });
+  if (res.errcode == 0) is_useList.value = res.data;
+  // 类型
+  res = await dictAxios.query({ type: 'home_tabs', is_use: '0' });
+  if (res.errcode == '0') typeList.value = res.data;
+};
+// 返回上一页
+const toBack = () => {
+  window.history.go(-1);
+};
+</script>
+<style scoped lang="scss"></style>

+ 9 - 70
src/views/content/article/index.vue

@@ -38,30 +38,6 @@
             </template>
           </cForm>
         </el-col>
-        <el-col :span="24" class="dialog_one" v-if="dialog.type == '2'">
-          <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="toSave" label-width="auto">
-            <template #file>
-              <cUpload
-                :model="`${'file'}`"
-                :limit="6"
-                listType="picture-card"
-                url="/files/travel/article/upload"
-                accept="*"
-                :list="form.file"
-                @change="onUpload"
-              ></cUpload>
-            </template>
-            <template #type>
-              <el-option v-for="i in typeList" :key="i.value" :label="i.label" :value="i.value"></el-option>
-            </template>
-            <template #content>
-              <cEditor v-model="form.content" url="/file/travel/article/upload"></cEditor>
-            </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>
@@ -70,10 +46,10 @@
 <script setup lang="ts">
 // 基础
 import store from '@/stores/counter';
-import type { FormRules } from 'element-plus';
 import type { Ref } from 'vue';
-import { ref, onMounted, getCurrentInstance, reactive } from 'vue';
+import { ref, onMounted, getCurrentInstance } from 'vue';
 import { ElMessage, ElMessageBox } from 'element-plus';
+import { useRouter } from 'vue-router';
 // 接口
 import { ArticleStore } from '@/stores/content/article';
 import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
@@ -82,6 +58,8 @@ const articleAxios = ArticleStore();
 const dictAxios = DictDataStore();
 const { proxy } = getCurrentInstance() as any;
 let user: Ref<any> = ref(store.state.user);
+// 路由
+const router = useRouter();
 // 加载中
 const loading: Ref<any> = ref(false);
 let list: Ref<any> = ref([]);
@@ -111,16 +89,9 @@ let typeList: Ref<any> = ref([]);
 
 // 弹框
 const dialog: Ref<any> = ref({ title: '信息管理', show: false, type: '1' });
-const form: Ref<any> = ref({ file: [] });
-const formFields: Ref<any> = ref([]);
-const rules = reactive<FormRules>({
-  title: [{ required: true, message: '标题', trigger: 'blur' }],
-  content: [{ required: true, message: '内容', trigger: 'blur' }],
-  type: [{ required: true, message: '类型', trigger: 'blur' }],
-  file: [{ required: true, message: '图片', trigger: 'blur' }],
-  create_time: [{ required: true, message: '创建时间', trigger: 'blur' }],
-  sort: [{ required: true, message: '排序', trigger: 'blur' }]
-});
+const form: Ref<any> = ref({});
+const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
+
 // 请求
 onMounted(async () => {
   loading.value = true;
@@ -147,13 +118,8 @@ const getDict = (value: any) => {
     else return '暂无';
   }
 };
-const onUpload = (e: { model: string; value: Array<[]> }) => {
-  const { model, value } = e;
-  form.value[model] = value;
-};
 // 审核
 const toExam = async (data: any) => {
-  formFields.value = [{ label: '状态', model: 'status', type: 'select' }];
   let res: IQueryResult = await articleAxios.fetch(data._id);
   if (res.errcode == '0') {
     form.value = res.data;
@@ -172,37 +138,11 @@ const toSave = async (data: any) => {
 };
 // 新增
 const toAdd = () => {
-  formFields.value = [
-    { label: '标题', model: 'title' },
-    { label: '类型', model: 'type', type: 'select' },
-    { label: '创建时间', model: 'create_time', type: 'datetime' },
-    { label: '排序', model: 'sort', type: 'number' },
-    { label: '图片', model: 'file', custom: true },
-    { label: '内容', model: 'content', custom: true },
-    { label: '是否启用', model: 'is_use', type: 'radio' }
-  ];
-  const info: any = { contact: user.value._id, contact_name: user.value.name };
-  if (user.value.type == '0') info.status = '1';
-  else info.status = '0';
-  form.value = info;
-  dialog.value = { title: '信息管理', show: true, type: '2' };
+  router.push({ path: '/content/article/detail' });
 };
 // 修改
 const toEdit = async (data: any) => {
-  formFields.value = [
-    { label: '标题', model: 'title' },
-    { label: '类型', model: 'type', type: 'select' },
-    { label: '创建时间', model: 'create_time', type: 'datetime' },
-    { label: '排序', model: 'sort', type: 'number' },
-    { label: '图片', model: 'file', custom: true },
-    { label: '内容', model: 'content', custom: true },
-    { label: '是否启用', model: 'is_use', type: 'radio' }
-  ];
-  let res: IQueryResult = await articleAxios.fetch(data._id);
-  if (res.errcode == '0') {
-    form.value = res.data;
-    dialog.value = { title: '信息管理', show: true, type: '2' };
-  }
+  router.push({ path: '/content/article/detail', query: { id: data._id } });
 };
 // 删除
 const toDel = async (data: any) => {
@@ -215,7 +155,6 @@ const toDel = async (data: any) => {
 
 // 关闭弹框
 const toClose = () => {
-  formFields.value = [];
   form.value = { file: [] };
   dialog.value = { show: false };
   search({ skip, limit });