Преглед изворни кода

feat: #初步完成一个页面(帮助分类)

loki пре 3 година
родитељ
комит
3d067a7621

+ 12 - 0
src/api/help/info.js

@@ -0,0 +1,12 @@
+import api from '@/utils/request';
+
+export const getList = params =>
+	api.post(`/yxl-back-end/framework/help/content/page`, params);
+export const getItem = ({ id, params }) =>
+	api.get(`/yxl-back-end/framework/help/content/${id}`, params);
+export const saveItem = params =>
+	api.post(`/yxl-back-end/framework/help/content/save`, params);
+export const delItem = ({ id, params }) =>
+	api.del(`/yxl-back-end/framework/help/content/${id}`, params);
+// export const getSMSCode = params =>
+//   api.post(`/yxl-back-end/framework/uiac/admin/mobile-number-sms/code`, params);

+ 65 - 0
src/components/BaseBtn.vue

@@ -0,0 +1,65 @@
+<template>
+  <el-popconfirm
+    v-if="popip"
+    :title="title"
+    :icon="icon"
+    :icon-color="iconColor"
+    @onConfirm="confirm"
+    @onCancel="cancel"
+  >
+    <el-button slot="reference" :type="type" v-bind="$attrs">{{
+      txt
+    }}</el-button>
+  </el-popconfirm>
+
+  <el-button
+    v-else
+    slot="reference"
+    :type="type"
+    v-bind="$attrs"
+    @click="$emit('click')"
+    >{{ txt }}</el-button
+  >
+</template>
+
+<script>
+export default {
+  name: 'BaseBtn',
+  props: {
+    popip: {
+      type: Boolean,
+      default: false
+    },
+    title: {
+      type: String,
+      default: '确定删除此记录?'
+    },
+    icon: {
+      type: String,
+      default: 'el-icon-warning-outline'
+    },
+    iconColor: {
+      type: String,
+      default: '#c01'
+    },
+    txt: {
+      type: String,
+      default: ''
+    },
+    type: {
+      type: String,
+      default: ''
+    }
+  },
+  methods: {
+    confirm() {
+      this.$emit('ok');
+    },
+    cancel() {
+      this.$emit('cancel');
+    }
+  }
+};
+</script>
+
+<style lang="scss" scoped></style>

+ 5 - 1
src/components/BaseTable.vue

@@ -39,7 +39,11 @@
                 <el-tag
                   size="medium"
                   :type="column.fetchTagType(scope.row[column.key]) || ''"
-                  >{{ scope.row[column.key] }}</el-tag
+                  >{{
+                    typeof column.tagName === 'function'
+                      ? column.tagName(scope.row)
+                      : scope.row[column.key]
+                  }}</el-tag
                 >
               </span>
               <span v-else>{{ scope.row[column.key] || '-' }}</span>

+ 2 - 0
src/components/index.js

@@ -1,9 +1,11 @@
 import Vue from 'vue';
+import BaseBtn from './BaseBtn.vue';
 import BaseTable from './BaseTable.vue';
 import Breadcrumb from './Breadcrumb.vue';
 import Hamburger from './Hamburger.vue';
 import SvgIcon from './SvgIcon.vue';
 
+Vue.component('BaseBtn', BaseBtn);
 Vue.component('BaseTable', BaseTable);
 Vue.component('Breadcrumb', Breadcrumb);
 Vue.component('Hamburger', Hamburger);

+ 3 - 0
src/const/type.js

@@ -0,0 +1,3 @@
+import { setStatus } from '@/utils';
+
+export default setStatus(['显示', '隐藏'], [1, 0]);

+ 2 - 1
src/containers/ToolbarContainer.vue

@@ -178,8 +178,9 @@ export default {
                 });
               }
               return init;
-            })
+            }, {})
           : [];
+      return filter;
     }
   }
 };

+ 4 - 1
src/mixins/filterList.js

@@ -40,7 +40,10 @@ const filterList = (params = {}) => ({
         size: this.pagination.pageSize
       };
 
-      const { data, msg } = await this.apiList(inParams);
+      const { data, msg } = await this.apiList(inParams, {
+        limit: this.pagination.pageSize,
+        start: this.pagination.page
+      });
       if (data in data) {
         const items = data.data;
         const total = {

+ 2 - 3
src/permission.js

@@ -32,9 +32,7 @@ router.beforeEach(async (to, from, next) => {
       } else {
         try {
           // get user info
-          const info = await store.dispatch('user/getInfo');
-          console.log(info);
-          let roles = [];
+          const { roles } = await store.dispatch('user/getInfo');
           // await store.dispatch('user/getInfo');
 
           // generate accessible routes map based on roles
@@ -49,6 +47,7 @@ router.beforeEach(async (to, from, next) => {
           next({ ...to, replace: true });
           // next()
         } catch (error) {
+          console.log('error');
           // remove token and go to login page to re-login
           await store.dispatch('user/resetToken');
           Message.error(error || 'Has Error');

+ 30 - 33
src/store/modules/user.js

@@ -34,39 +34,36 @@ const mutations = {
 const actions = {
   // user login
   login({ commit }, userInfo) {
-    console.log(userInfo);
     const { phone, code } = userInfo;
-    return new Promise((resolve, reject) => {
-      const data = {
-        token: 'admin-token'
-      };
-      commit('SET_TOKEN', data.token);
-      setToken(data.token);
-      resolve();
-    });
     // return new Promise((resolve, reject) => {
-    //   login({
-    //     data: {
-    //       account: phone,
-    //       signInType: 'MOBILE_NUMBER_SMS',
-    //       smsCode: code
-    //     }
-    //   })
-    //     .then(response => {
-    //       const { data } = response;
-
-    //       if (data.token) {
-    //         commit('SET_TOKEN', data.token);
-    //         setToken(data.token);
-    //         resolve();
-    //       } else {
-    //         reject(data.message);
-    //       }
-    //     })
-    //     .catch(error => {
-    //       reject(error);
-    //     });
+    //   const data = {
+    //     token: 'admin-token'
+    //   };
+    //   commit('SET_TOKEN', data.token);
+    //   setToken(data.token);
+    //   resolve();
     // });
+    return new Promise((resolve, reject) => {
+      login({
+        account: phone,
+        signInType: 'MOBILE_NUMBER_SMS',
+        smsCode: code
+      })
+        .then(response => {
+          const { data } = response;
+
+          if (data.token) {
+            commit('SET_TOKEN', data.token);
+            setToken(data.token);
+            resolve();
+          } else {
+            reject(data.message);
+          }
+        })
+        .catch(error => {
+          reject(error);
+        });
+    });
   },
 
   // get user info
@@ -92,6 +89,7 @@ const actions = {
     return new Promise((resolve, reject) => {
       getInfo(state.token)
         .then(async response => {
+          console.log(response);
           const { data, success } = response;
 
           if (!success) {
@@ -99,14 +97,13 @@ const actions = {
             return reject('Verification failed, please Login again.');
           }
 
-          const { name, avatar, roles } = data;
+          const { nickname, avatar, roles } = data;
 
           // const roles = [];
 
           commit('SET_ROLES', roles);
-          commit('SET_NAME', name);
+          commit('SET_NAME', nickname);
           commit('SET_AVATAR', avatar);
-
           // dispatch('permission/generateRoutes');
           resolve(data);
         })

+ 53 - 38
src/utils/index.js

@@ -10,28 +10,28 @@
  */
 export function parseTime(time, cFormat) {
   if (arguments.length === 0 || !time) {
-    return null
+    return null;
   }
-  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
-  let date
+  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}';
+  let date;
   if (typeof time === 'object') {
-    date = time
+    date = time;
   } else {
-    if ((typeof time === 'string')) {
-      if ((/^[0-9]+$/.test(time))) {
+    if (typeof time === 'string') {
+      if (/^[0-9]+$/.test(time)) {
         // support "1548221490638"
-        time = parseInt(time)
+        time = parseInt(time);
       } else {
         // support safari
         // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
-        time = time.replace(new RegExp(/-/gm), '/')
+        time = time.replace(new RegExp(/-/gm), '/');
       }
     }
 
-    if ((typeof time === 'number') && (time.toString().length === 10)) {
-      time = time * 1000
+    if (typeof time === 'number' && time.toString().length === 10) {
+      time = time * 1000;
     }
-    date = new Date(time)
+    date = new Date(time);
   }
   const formatObj = {
     y: date.getFullYear(),
@@ -41,14 +41,16 @@ export function parseTime(time, cFormat) {
     i: date.getMinutes(),
     s: date.getSeconds(),
     a: date.getDay()
-  }
+  };
   const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
-    const value = formatObj[key]
+    const value = formatObj[key];
     // Note: getDay() returns 0 on Sunday
-    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
-    return value.toString().padStart(2, '0')
-  })
-  return time_str
+    if (key === 'a') {
+      return ['日', '一', '二', '三', '四', '五', '六'][value];
+    }
+    return value.toString().padStart(2, '0');
+  });
+  return time_str;
 }
 
 /**
@@ -58,27 +60,27 @@ export function parseTime(time, cFormat) {
  */
 export function formatTime(time, option) {
   if (('' + time).length === 10) {
-    time = parseInt(time) * 1000
+    time = parseInt(time) * 1000;
   } else {
-    time = +time
+    time = +time;
   }
-  const d = new Date(time)
-  const now = Date.now()
+  const d = new Date(time);
+  const now = Date.now();
 
-  const diff = (now - d) / 1000
+  const diff = (now - d) / 1000;
 
   if (diff < 30) {
-    return '刚刚'
+    return '刚刚';
   } else if (diff < 3600) {
     // less 1 hour
-    return Math.ceil(diff / 60) + '分钟前'
+    return Math.ceil(diff / 60) + '分钟前';
   } else if (diff < 3600 * 24) {
-    return Math.ceil(diff / 3600) + '小时前'
+    return Math.ceil(diff / 3600) + '小时前';
   } else if (diff < 3600 * 24 * 2) {
-    return '1天前'
+    return '1天前';
   }
   if (option) {
-    return parseTime(time, option)
+    return parseTime(time, option);
   } else {
     return (
       d.getMonth() +
@@ -90,7 +92,7 @@ export function formatTime(time, option) {
       '时' +
       d.getMinutes() +
       '分'
-    )
+    );
   }
 }
 
@@ -99,19 +101,32 @@ export function formatTime(time, option) {
  * @returns {Object}
  */
 export function param2Obj(url) {
-  const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
+  const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ');
   if (!search) {
-    return {}
+    return {};
   }
-  const obj = {}
-  const searchArr = search.split('&')
+  const obj = {};
+  const searchArr = search.split('&');
   searchArr.forEach(v => {
-    const index = v.indexOf('=')
+    const index = v.indexOf('=');
     if (index !== -1) {
-      const name = v.substring(0, index)
-      const val = v.substring(index + 1, v.length)
-      obj[name] = val
+      const name = v.substring(0, index);
+      const val = v.substring(index + 1, v.length);
+      obj[name] = val;
     }
-  })
-  return obj
+  });
+  return obj;
 }
+/**
+ * 若第二数组不设置默认根据下标数设置
+ * @param  {[type]} label [显示文案数组]
+ * @param  {[type]} value [表示值的数组]
+ * @return {[type]}       [description]
+ */
+export const setStatus = (label, value) => {
+  let res = label.map((x, i) => ({
+    label: x,
+    value: value.length > i ? value[i] : i
+  }));
+  return res;
+};

+ 17 - 13
src/utils/request.js

@@ -166,19 +166,11 @@ const formatCode = ({ code, data, msg }) => {
   //     data: {}
   //   }
   // }
-  if (code !== 200) {
-    return {
-      code: code,
-      success: false,
-      msg,
-      data: {}
-    };
-  }
   return {
-    success: data.code === 200,
-    msg: data.msg,
-    code: data.code,
-    data: data.data
+    success: code === 200,
+    msg,
+    code,
+    data
   };
 };
 
@@ -307,6 +299,8 @@ const delData = (url, data = {}, params, config) => {
 };
 
 const post = (url, data = {}, config) => {
+  console.log(data);
+  console.log(config);
   config = pretreatConfig(config);
   config = Object.assign(
     {
@@ -317,7 +311,17 @@ const post = (url, data = {}, config) => {
     config
   );
   return formatResponse(
-    axios.post(url, { data, seq: config.seq, token: config.token }, config)
+    axios.post(
+      url,
+      {
+        data,
+        seq: config.seq,
+        token: config.token,
+        limit: data.size,
+        start: data.page
+      },
+      config
+    )
   );
 };
 

+ 4 - 3
src/views/helpInfo/information/index.vue

@@ -19,6 +19,7 @@
 <script>
 import toolbar from './toolbar';
 import mxFilterList from '@/mixins/filterList';
+import { getList, delItem } from '@/api/help/info';
 
 export default {
   name: 'Information',
@@ -35,8 +36,8 @@ export default {
     return {
       columns: [
         {
-          key: 'photo',
-          name: 'ID',
+          key: 'name',
+          name: '标题',
           width: '160'
         },
         {
@@ -60,7 +61,7 @@ export default {
           width: '180'
         },
         {
-          key: 'region',
+          key: 'isShow',
           name: '状态',
           width: '180'
         },

+ 25 - 31
src/views/helpInfo/issueType/index.vue

@@ -13,7 +13,6 @@
         :pagination="pagination"
         :page-change="pageChange"
       />
-      {{ items }}
     </div>
   </div>
 </template>
@@ -52,21 +51,19 @@ export default {
           name: '排序',
           width: '120'
         },
-        // {
-        //   key: 'region',
-        //   name: '创建时间',
-        //   width: '180'
-        // },
-        // {
-        //   key: 'region',
-        //   name: '备注',
-        //   width: '180'
-        // },
-        // {
-        //   key: 'region',
-        //   name: '状态',
-        //   width: '180'
-        // },
+        {
+          key: 'createAt',
+          name: '创建时间',
+          minWidth: '180'
+        },
+        {
+          key: 'isShow',
+          name: '状态',
+          width: '180',
+          type: 'tag',
+          fetchTagType: val => (val ? 'success' : 'info'),
+          tagName: row => (row.isShow ? '显示' : '隐藏')
+        },
         {
           key: 'action',
           name: '操作',
@@ -110,29 +107,22 @@ export default {
             );
             action.push(
               h(
-                'el-popcomfirm',
+                'BaseBtn',
                 {
                   props: {
-                    icon: 'el-icon-warning-outline',
-                    iconColor: '#c01',
-                    title: '确定要删除吗?'
+                    popip: true,
+                    txt: '删除',
+                    type: 'text'
                   },
+                  class: 'ml-10',
                   on: {
-                    confirm: () => this.handleDelItem(row)
+                    ok: () => this.handleDelItem(row)
                   }
                 },
-                h(
-                  'el-button',
-                  {
-                    props: {
-                      type: 'text',
-                      solt: 'reference'
-                    }
-                  },
-                  '删除'
-                )
+                '删除'
               )
             );
+
             return h('div', action);
           }
         }
@@ -146,16 +136,19 @@ export default {
         {
           id: 998,
           name: 'sex',
+          isShow: true,
           sort: 10,
           children: [
             {
               id: 31,
               name: 'man',
+              isShow: false,
               sort: 9,
               children: [
                 {
                   id: 312,
                   name: 'man',
+                  isShow: true,
                   sort: 9
                 }
               ]
@@ -163,6 +156,7 @@ export default {
             {
               id: 9,
               name: 'woman',
+              isShow: true,
               sort: 7
             }
           ]

+ 1 - 1
src/views/helpInfo/issueType/modal/ItemModal.vue

@@ -114,7 +114,7 @@ export default {
           if (!this.form.parentId) {
             params.parentId = this.parentId;
           }
-          const { success, msg } = await saveItem({ data: params });
+          const { success, msg } = await saveItem(params);
           if (success) {
             this.$success('保存成功!');
             this.modal = false;

+ 5 - 1
src/views/helpInfo/issueType/toolbar.vue

@@ -3,6 +3,8 @@
 </template>
 
 <script>
+import TYPE from '@/const/type';
+
 export default {
   name: 'IssueTypeToolbar',
 
@@ -18,7 +20,9 @@ export default {
           type: 'select',
           name: 'status',
           label: '状态',
-          labelWidth: '100px'
+          labelWidth: '100px',
+          options: TYPE,
+          format: val => (val !== null ? !!val : null)
         }
       ]
     };

+ 0 - 1
src/views/login/index.vue

@@ -138,7 +138,6 @@ export default {
   },
   methods: {
     handleLogin() {
-      console.log('------------');
       this.$refs.loginForm.validate(valid => {
         if (valid) {
           this.loading = true;