Ver Fonte

add:
轮播管理接口测试

kindring há 2 anos atrás
pai
commit
e048791336

+ 21 - 4
components/header/menuDrops/menuDrop.vue

@@ -35,6 +35,8 @@
 <script>
 import langMap from "~/map/langMap";
 import handle from "~/until/handle";
+import {indexTypes} from "../../../store";
+import {mapGetters} from "vuex";
 import {productMenus} from "~/map/productMap";
 /**
  * 解决方案
@@ -66,6 +68,11 @@ export default {
     type:{default:'product'},
     pHref: {default:''}
   },
+  computed:{
+      products(){return this.$store.getters.productTypes},
+      solutions(){return this.$store.getters.solutionTypes},
+  },
+  // 使用vuex getter 获取数据
   data(){
     return {
       langType: langMap.lang,
@@ -77,10 +84,17 @@ export default {
       nowSubMenuId: ""
     }
   },
+
   beforeMount() {
     this.loadMenus();
-    this.nowMenuKey = this.menus[0].typeKey;
-    this.loadMenuItems();
+    console.log(this.menus);
+    if(this.menus && this.menus.length){
+      this.nowMenuKey = this.menus[0].typeKey;
+      this.loadMenuItems();
+    }else{
+      console.log('no menu data');
+    }
+
   },
   methods:{
     getLangText(str){
@@ -92,10 +106,13 @@ export default {
     loadMenus(){
       if(this.type === "solution"){
         console.log("solution data")
-        this.menus = solutionMenus;
+        this.menus = this.solutions;
+        console.log(this.menus);
       }else{
-        this.menus = productMenus;
+        this.menus = this.products;
+        console.log(this.menus);
       }
+
     },
     subItemHandle(id){
       this.nowSubMenuId = id;

+ 3 - 0
components/search/searchBox.vue

@@ -42,6 +42,9 @@ export default {
       domPlaceholder: [],//当前的数据列表
     }
   },
+  mounted() {
+    this.loadData(1,true)
+  },
   methods: {
     async loadData(page,isPush){
       if(isPush){

+ 8 - 0
map/dbField_esm.js

@@ -29,6 +29,14 @@ export const db_base = {
     production: 1,
     news: 2,
     page: 3,
+  },
+  // 文章类型分类
+  newsType: {
+    all: -1,
+    // 解决方案
+    solution: 1,
+    // 新闻
+    news: 2,
   }
 }
 

+ 150 - 44
pages/manger/index/carousel.vue

@@ -20,7 +20,18 @@ export default defineComponent({
   computed: {
     dbField_esm() {
       return dbField_esm
-    }
+    },
+    productTypes(){
+      let arr = this.$store.getters.productTypes;
+      // 添加 all
+      arr.unshift({text: '全部', key: 'all' });
+      return arr;
+    },
+    newsTypes(){// 添加 all
+      let arr = this.$store.getters.allNewsTypes;
+      arr.unshift({text: '全部', key: 'all' });
+      return arr;
+    },
   },
   components: {SearchBox, InputRow, PopCard, Pop, ImageTable, ImageViewer, RoundedTitle},
   async asyncData(ctx){
@@ -45,7 +56,7 @@ export default defineComponent({
       carouselList: [],
       popShow: false,
       popLoading: false,
-      carouselPopShow: true,
+      carouselPopShow: false,
       carouselPopLoading: false,
       isEditCarousel: false,
       carouselData: {},
@@ -64,13 +75,6 @@ export default defineComponent({
           msg: '',
           state: 0,
         },
-        // 图像资源id, 0为无图
-        file: {
-          val: 0,
-          init: 0,
-          msg: '',
-          state: 0,
-        },
         // 轮播类型 '0:product','1:news','2:page','3:href'
         type: {
           val: 0,
@@ -78,10 +82,9 @@ export default defineComponent({
           msg: '',
           state: 0,
           options: [
-            {label: '直接链接', value: 0},
-            {label: '内部产品', value: 1},
-            {label: '指向新闻', value: 2},
-            {label: '内部页面', value: 3},
+            {label: '直接链接', value: 0,checkField: 'href'},
+            {label: '内部产品', value: 1,checkField: 'productId'},
+            {label: '指向新闻', value: 2,checkField: 'newsId'},
           ],
         },
         // 具体值
@@ -90,6 +93,8 @@ export default defineComponent({
           init: '',
           msg: '',
           state: 0,
+          // 依赖字段
+          depend: 'type',
           showText: '',// 展示用字段
           oldShowText: '',
         },
@@ -106,25 +111,24 @@ export default defineComponent({
       productSelectVisible: false,
       productSearch: {
         type: {
-          val: pTypes[0].key,
-          oldVal: pTypes[0].key,
-          init: pTypes[0].key,
+          val: '',
+          oldVal: '',
+          init: '',
           msg: '',
-          options: pTypes,
+          options: [],
         }
       },
       newsSelectVisible: false,
       newsVisible: false,
       newsSearch: {
         type: {
-          val: newsType[0].key,
-          oldVal: newsType[0].key,
-          init: newsType[0].key,
+          val: '',
+          oldVal: '',
+          init: '',
           msg: '',
-          options: pTypes,
+          options: [],
         }
       },
-
       imageSelectVisible: false,
 
     }
@@ -213,8 +217,38 @@ export default defineComponent({
       }
     },
     // 加载轮播默认数据
+    async getNewsSearch(searchParam){
+      console.log(searchParam)
+      if(this.newsSearch.type.val !== this.newsSearch.type.oldVal){
+        searchParam.p = 1;
+      }
+      searchParam.type = this.newsSearch.type.val;
+      searchParam.l = this.limit;
+      searchParam.p = searchParam.page;
+      let [err,res] = await handle(
+        this.$axios.get(
+          apiMap.searchNewsMini.path,
+          {params:searchParam})
+      );
+      if(err){
+        console.log(err);
+        return [{message:'请求数据失败'},null];
+      }
 
-
+      let result = res.data;
+      if(result.code === rCode.OK){
+        this.newsSearch.type.oldVal = this.newsSearch.type.val;
+        // data 转换
+        result.data = result.data.map(item=>{
+          item.showText=item.name;
+          return item;
+        });
+        return [null,result];
+      }else{
+        // 可捕获的服务器错误
+        return [{message:result.msg},null];
+      }
+    },
     checkFormItem(field,enumOptions,reCheckField){
       let formItem = this.form[field];
       if (formItem){
@@ -242,10 +276,48 @@ export default defineComponent({
       }else{
         let r = true;
         for (const fieldKey in this.form) {
-          this.form[fieldKey].msg = fieldIsAllow({
-            [fieldKey]:this.form[fieldKey].val,
+          formItem = this.form[fieldKey];
+          let depend = this.form[formItem.depend];
+          let checkField = fieldKey;
+
+          if(formItem.reCheckField){
+            checkField = formItem.reCheckField;
+          }
+          // 枚举值判断
+          if(formItem.options){
+            // 有枚举字段,只判断是否在枚举中
+            if(formItem.options.findIndex(item=>item.value == formItem.val) === -1){
+              formItem.msg = '选项不在范围内';
+              r = false;
+            }
+            // 枚举值判断完毕,继续下一个字段
+            continue;
+          }
+
+          // 判断是否有依赖字段
+          if(depend){
+            if(depend.options){
+              // 依赖的对象有枚举类型,检查该枚举类型是否有有检测值
+              let optionItem = depend.options.find(item=>item.value == depend.val);
+              if(!optionItem){
+                depend.msg = '选项不在范围内';
+                formItem.msg = '该值依赖项输入异常';
+                r = false;
+                continue;
+              }
+              if(optionItem.checkField){
+                console.log(`采用依赖项的检测字段${optionItem.checkField}`)
+                checkField = optionItem.checkField;
+              }
+
+            }
+          }
+
+          console.log(`检测字段:${checkField},值:${formItem.val}`);
+          formItem.msg = fieldIsAllow({
+            [checkField]:formItem.val,
           })
-          if (this.form[fieldKey].msg){
+          if (formItem.msg){
             r = false;
           }
         }
@@ -263,15 +335,44 @@ export default defineComponent({
         this.form.value.showText = '';
       }
     },
-
     openAddCarouselModal(){
       // 初始化表单
       this.initCarouseForm();
-      // 打开弹窗. 选择图片,填写链接地址,排序
       this.carouselPopShow = true;
       this.isEditCarousel = false;
+      this.$nextTick(()=>{
+        // 打开弹窗. 选择图片,填写链接地址,排序
+        this.productSearch.type.options = this.productTypes;
+        this.newsSearch.type.options = this.newsTypes;
+        // 默认值设置
+        this.productSearch.type.val = this.productTypes[0].key;
+        this.productSearch.type.oldVal = this.productTypes[0].key;
+        this.productSearch.type.init = this.productTypes[0].key;
+
+        this.newsSearch.type.val = this.newsTypes[0].key;
+        this.newsSearch.type.oldVal = this.newsTypes[0].key;
+        this.newsSearch.type.init = this.newsTypes[0].key;
+
+
+      });
     },
+    onPopOkClickHandle(){
+      if(this.isEditCarousel){
+        console.log('保存修改后的轮播数据');
+      }else{
+        console.log('新增轮播图');
+        this.addCarouselExecute();
+      }
+    },
+    addCarouselExecute(){
+      // 生成新数据表单
+      let carouselData = {};
+      let isPass = this.checkFormItem();
+      if(!isPass){
+        return console.log('数据验证不通过');
+      }
 
+    },
 
 
 
@@ -297,24 +398,28 @@ export default defineComponent({
       console.log(`onProductSearchHandle ${e}`);
       console.log(e);
       console.log(this.productSearch.type.val);
-      // this.productSearch.type
     },
     onSelectedItemHandle(item){
       console.log(`selected item ${item}`);
       console.log(item);
       this.form.value.val = item.id;
       this.form.value.showText = item.showText;
+      this.form.value.msg = '';
     },
     onTypeChangeHandle(e){
       console.log(`type change ${e}`);
       // 清除其他值
+      this.form.value.val = '';
       this.form.value.msg = '';
       this.form.value.showText = '';
     },
-    loadDefaultProductItem(){
-      this.productSearch.type.val = pTypes[0].key;
-      this.$refs.productSearch.loadData(1,true);
+
+    onNewsSearchHandle(e){
+      console.log(`onProductSearchHandle ${e}`);
+      console.log(e);
+      console.log(this.productSearch.type.val);
     },
+
   },
 
 })
@@ -371,7 +476,8 @@ export default defineComponent({
          <input-row :msg="form.sort.msg"
                     label="排序">
            <a-input-number v-model="form.sort.val"
-                           @focus="form.password.msg=''"
+                           @focus="form.sort.msg=''"
+                           :min="0"
                            @blur="checkFormItem('sort')"
            />
          </input-row>
@@ -414,7 +520,6 @@ export default defineComponent({
                 :limit="limit"
                 search-placeholder="请输入产品名称关键字"
                 loadTip="正在搜索产品中..."
-                ref="productSearch"
                 @onSelectedItem="onSelectedItemHandle"
               >
                 <div class="w-full" slot="otherSearchItem">
@@ -429,22 +534,22 @@ export default defineComponent({
                 </div>
               </search-box>
             </div>
-            <a-button type="primary" @click="loadDefaultProductItem">
+            <a-button type="primary" >
               选择产品
             </a-button>
           </a-popover>
         </input-row>
 <!--        新闻选择-->
         <input-row
-          v-show="form.type.val === dbField_esm.db_base.carouselType.production"
+          v-show="form.type.val === dbField_esm.db_base.carouselType.news"
           :msg="form.value.msg"
           label="文章选择">
           {{ form.value.showText }}
-          <a-popover  v-model="productSelectVisible" title="选择你需要的文章" trigger="click">
+          <a-popover  v-model="newsSelectVisible" title="选择你需要的文章" trigger="click">
             <div slot="content" class="searchBox" >
               <search-box
                 class="h-72"
-                :loadDataApi="getProductSearch"
+                :loadDataApi="getNewsSearch"
                 :limit="limit"
                 search-placeholder="请输入产品名称关键字"
                 loadTip="正在搜索产品中..."
@@ -452,9 +557,9 @@ export default defineComponent({
                 @onSelectedItem="onSelectedItemHandle"
               >
                 <div class="w-full" slot="otherSearchItem">
-                  <a-radio-group v-model="productSearch.type.val"
-                                 @change="onProductSearchHandle">
-                    <a-radio-button v-for="opt in productSearch.type.options"
+                  <a-radio-group v-model="newsSearch.type.val"
+                                 @change="onNewsSearchHandle">
+                    <a-radio-button v-for="opt in newsSearch.type.options"
                                     :key="'cType'+opt.key"
                                     :value="opt.key">
                       {{ opt.text }}
@@ -463,14 +568,15 @@ export default defineComponent({
                 </div>
               </search-box>
             </div>
-            <a-button type="primary" @click="loadDefaultProductItem">
+            <a-button type="primary">
               选择产品
             </a-button>
           </a-popover>
         </input-row>
 
 <!--        选择图片 -->
-        <input-row label="轮播图片">
+        <input-row label="轮播图片"
+                   :msg="form.fileData.msg">
           <a-popover  v-model="imageSelectVisible"
                       class="w-full"
                      trigger="click">
@@ -492,7 +598,7 @@ export default defineComponent({
         </input-row>
       </div>
       <template class="w-full" slot="footer">
-        <a-button>{{isEditCarousel? '保存': '新增'}}</a-button>
+        <a-button @click="onPopOkClickHandle">{{isEditCarousel? '保存': '新增'}}</a-button>
       </template>
     </pop-card>
   </pop>

+ 73 - 2
server/control/c_base.js

@@ -1,5 +1,7 @@
 const {handle, handleAll} = require('../tools/handle_cjs');
 const d_base = require("../database/d_base");
+const d_product = require("../database/d_product");
+const d_news = require("../database/d_news");
 const codeMap = require("../map/rcodeMap");
 const dbField = require("../map/dbField");
 const {searchHandle} = require("../tools/searchSql");
@@ -26,6 +28,58 @@ async function getCarousel(){
   return [null,res];
 }
 
+async function addCarousel(sort,fileId,type,value){
+  let err,res;
+  let valueData = {};
+  let valueShowText = '';
+  let updateTime = getUnixTimeStamp();
+  // 根据type判断value
+  if(type !== dbField.db_base.carouselType.href){
+    if(type === dbField.db_base.carouselType.product){
+      // 获取产品信息
+      [err,res] = await handle(d_product.getProductById(value));
+    }else if(type === dbField.db_base.carouselType.news){
+      // 获取新闻信息
+      [err,res] = await handle(d_news.getNewsById(value));
+    }
+    if(err){
+      console.log(err);
+      log.info(`[新增轮播] 检索产品信息失败`);
+      return [{eCode: codeMap.ServerError, eMsg: `检索数据异常`},null];
+    }
+    if(isEmpty(res)){
+      log.info(`[新增轮播] 无法找到对应的产品或者文章信息`);
+      return [{eCode: codeMap.NotFound, eMsg: `无法找到对应的产品或者文章信息`},null];
+    }
+    valueData = res[0];
+  }
+  valueShowText = valueData.title;
+  [err,res] = await handle(d_base.addCarousel(
+    sort,fileId,type,value,valueShowText,updateTime
+  ));
+  if(err){
+    log.info(`[新增轮播] 导入数据异常`)
+    return [err,null];
+  }
+  return [null,res];
+}
+
+async function deleteCarousel(id){
+  let err,res;
+  [err,res] = await handle(d_base.deleteCarousel(id));
+  if(err){
+    log.info(`[删除轮播] 删除数据异常`);
+    return [err,null];
+  }
+  return [null,res];
+}
+
+async function updateCarousel(id,updateParam){
+  let err,res;
+  return [null,res];
+}
+
+
 /**
  * 文件上传
  * @param type
@@ -147,16 +201,33 @@ async function deleteFile(fileId){
 }
 
 
-function getTypes(){
+async function getTypes(){
   // 同时获取所有需要获取的基础数据
   let err,pType,nType;
   // todo 同时获取所有需要获取的基础数据
+  [err,pType,nType] = await handleAll(
+    d_product.loadTypes(),
+    d_news.loadTypes()
+  );
+  if (err) {
+    log.error(`[基础数据] 获取基础数据类型分类失败 ${err.message}`);
+    return [{eCode: codeMap.ServerError, eMsg: `获取基础数据失败`}, null];
+  }
+  // 合并数据
+  let types = {
+    pType,
+    nType
+  };
+  log.info(`[基础数据] 类型分类获取成功 程序类型数量:${pType.length} 文章类型数量:${nType.length}`);
+  return [null,types];
 }
 module.exports = {
   getCarousel,
   uploadFile,
   searchFiles,
-  deleteFile
+  deleteFile,
+  getTypes,
+  addCarousel
 }
 
 

+ 7 - 0
server/database/d_base.js

@@ -25,6 +25,12 @@ function getCarousel(){
   return mysql.pq(sql);
 }
 
+function addCarousel(sort,fileId,type,value,valueShowText,updateTime){
+  let sql = `INSERT INTO hfy_carousel (sort, fileId, type, value, valueShowText, updateTime)
+                    VALUES (?,?,?,?,?,?)`;
+  return mysql.pq(sql,[sort,fileId,type,value,valueShowText,updateTime]);
+}
+
 function uploadFiles(type,fileNameArr,uploadTime){
   let sql = `INSERT INTO hfy_files (fileType, filePath, uploadTime)
                     VALUES ${fileNameArr.map(f=>`(?,?,?)`).join(',')}`;
@@ -87,4 +93,5 @@ module.exports = {
   loadFiles,
   getFileById,
   deleteFile,
+  addCarousel
 }

+ 42 - 0
server/database/d_news.js

@@ -8,6 +8,48 @@ function addReadNum(id){
    return mysql.pq(sql,values);
 }
 
+function loadTypes() {
+  let sql = `SELECT * FROM hfy_news_type`;
+  return mysql.pq(sql, []);
+}
+
+// 轻量搜索接口
+function searchAllNewsMini(type='array',searchParam,page,limit){
+  let sql;
+  let values = [];
+  if(type === 'count'){
+    sql = `select count(*) as total `;
+  }else{
+    sql = `select
+    news.id as id ,
+    news.title as name,
+    n_type.type_key
+    `;
+  }
+  sql += `
+   from
+   hfy_news as news ,
+   hfy_news_type as n_type
+  `
+  sql += ` where news.type_id = n_type.type_id`
+  if(searchParam.key){
+    sql += ` and news.title like '%${searchParam.key}%'`
+  }
+  if(searchParam.type){
+    sql += ` and n_type.type_key = ?`
+    values.push(searchParam.type)
+  }
+  return searchSql(mysql.pq,type,sql,values,limit,page);
+}
+
+function getNewsById(id){
+  let sql = `SELECT * FROM hfy_product WHERE id = ? limit 1`;
+  return mysql.pq(sql,[id]);
+}
+
 module.exports = {
   addReadNum,
+  loadTypes,
+  searchAllNewsMini,
+  getNewsById
 }

+ 12 - 1
server/database/d_product.js

@@ -98,9 +98,20 @@ function searchProductsByMini(type='array',searchParam,page,limit){
   return searchSql(mysql.pq,type,sql,values,limit,page);
 }
 
+function loadTypes() {
+  let sql = `SELECT * FROM hfy_product_type`;
+  return mysql.pq(sql, []);
+}
+
+function getProductById(id){
+  let sql = `SELECT *,name as title FROM hfy_product WHERE proid = ? limit 1`;
+  return mysql.pq(sql,[id]);
+}
 module.exports = {
   loadProducts,
   getProductInfo,
   searchProducts,
-  searchProductsByMini
+  searchProductsByMini,
+  loadTypes,
+  getProductById
 }

+ 14 - 0
server/map/dbField.js

@@ -20,6 +20,20 @@ const db_base = {
     other: 0,
     image: 1,
     video: 2,
+  },
+  carouselType: {
+    href: 0,
+    production: 1,
+    news: 2,
+    page: 3,
+  },
+  // 文章类型分类
+  newsType: {
+    all: -1,
+    // 解决方案
+    solution: 1,
+    // 新闻
+    news: 2,
   }
 }
 

+ 46 - 3
server/router/r_base.js

@@ -12,7 +12,7 @@ const upload = require("../middleware/upload");
 const config_path = require("../configs/path");
 const log = require("../logger").logger("r_base","info");
 
-router.get('/carousel', checkLogin(progressField.session_hfy), async (req, res) => {
+router.get('/carousel', async (req, res) => {
   try{
     let [err, data] = await c.getCarousel();
     if(err){
@@ -24,6 +24,49 @@ router.get('/carousel', checkLogin(progressField.session_hfy), async (req, res)
     ServerError(res, e, `获取轮播图失败 ${e.message}`);
   }
 });
+
+router.put('/carousel', checkLogin(progressField.session_hfy), async (req, res) => {
+  try{
+    log.info(`[轮播图新增] 开始新增轮播图`);
+    // 获取轮播数据
+    let {sort,fileId,type,value} = req.body;
+    let err,data;
+    // 检测参数
+    if(isEmpty(sort) || isEmpty(fileId) || isEmpty(type) || isEmpty(value)){
+      return paramFail(res, '缺少必要参数');
+    }
+    [err,data] = await c.addCarousel(sort,fileId,type,value);
+    if(err){
+      controlError(res, err,`新增轮播图失败 ${err.eMsg||err.message}`);
+    }else{
+      success(res, data);
+    }
+  }catch (e){
+    ServerError(res, e, `新增轮播图接口异常 ${e.message}`);
+  }
+});
+
+router.post('/carousel', checkLogin(progressField.session_hfy), async (req, res) => {
+  try{
+    log.info(`[轮播图修改] 开始修改轮播图数据`);
+    // 获取轮播数据
+    let {carouselId,changeParams} = req.body;
+    let err,data;
+    // 检测参数
+    if(isEmpty(carouselId) || isEmpty(changeParams) ){
+      return paramFail(res, '缺少必要参数');
+    }
+    [err,data] = await c.changeCarousel(carouselId,changeParams);
+    if(err){
+      controlError(res, err,`轮播图修改 ${err.eMsg||err.message}`);
+    }else{
+      success(res, data);
+    }
+  }catch (e){
+    ServerError(res, e, `轮播图修改接口异常 ${e.message}`);
+  }
+});
+
 router.get('/files', checkLogin(progressField.session_hfy), async (req, res) => {
   try{
     let err, result;
@@ -95,9 +138,9 @@ router.delete('/file/:fileId',checkLogin(progressField.session_hfy),async (req,r
   }
 })
 
-router.get('/types',checkLogin(progressField.session_hfy),async (req,res)=>{
+router.get('/types',async (req,res)=>{
   try{
-    log.info(`[类型] 获取基础类型信息`)
+    log.info(`[类型] 获取基础类型信息`);
     // 从数据库中读取数据.
     let [err, data] = await c.getTypes();
     if(err){

+ 1 - 1
server/tools/handle_cjs.js

@@ -32,7 +32,7 @@ function handleAll() {
             // console.log(arr)
             // console.log(typeof arr)
             Promise.all(arr).then(val => {
-                console.log(val);
+                // console.log(val);
                 resolve([null, ...val])
             }).catch(err => {
                 console.log(err)

+ 7 - 1
server/tools/typeTool_cjs.js

@@ -50,17 +50,23 @@ function isObject(v){
     return v instanceof Object
 }
 
-// 判断 obj 或者 arr 是否为空
+// 判断 obj 或者 arr 是否为空 , 允许为0, 不允许空字符串
 function isEmpty(v){
     if(isArray(v)){
         return v.length === 0
     }else if(isObject(v)){
         return Object.keys(v).length === 0
+    }else if(v === 0){
+        return true;
     }else{
         return !v
     }
 }
 
+// 判断数据是否存在,不允许为空字符串,空对象与空数组, 允许为 0
+
+
+
 module.exports = {
     toNumber,
     toString,

+ 52 - 8
store/index.js

@@ -1,8 +1,27 @@
 import {login_types,state,mutations,actions,getters} from "./login";
-import indexTypes from "./indexStoreTypes";
 import login from "./login";
-import {apiMap} from "../map/apiMap";
+import {apiMap, baseUrl} from "../map/apiMap";
+import {rCode} from "../map/rcodeMap_esm";
+import handle from "../until/handle";
+import axios from "axios";
+import dbField_esm from "../map/dbField_esm";
 
+function _transform(arr){
+  arr = arr.map(item => {
+    item.text = item.type_name;
+    item.key = item.type_key;
+    item.typeKey = item.type_key;
+    item.href = `/${item.type_key}`;
+    return item;
+  })
+  return arr;
+}
+export const indexTypes = {
+  mutations: {
+    setProductTypes: 'setProductTypes',
+    setNewsTypes: 'setNewsTypes',
+  }
+}
 
 export const modules = {
   index: {
@@ -13,10 +32,10 @@ export const modules = {
       nTypes: [],
     },
     mutations: {
-      [indexTypes.mutations.setProductTypes](state, pTypes) {
+      [indexTypes.mutations.setProductTypes](state, pTypes){
         state.pTypes = pTypes;
       },
-      [indexTypes.mutations.setNewsTypes](state, nTypes) {
+      [indexTypes.mutations.setNewsTypes](state, nTypes){
         state.nTypes = nTypes;
       }
     },
@@ -29,15 +48,40 @@ export const modules = {
           }
           // 获取新闻与产品类别信息
           let err, res;
-          [err, res] = await this.$axios.$get(apiMap.baseTypes.path);
+          [err, res] = await handle(axios.get(baseUrl + apiMap.baseTypes.path));
           if(err){return console.log(err);}
-          if(res.code !== rCode.OK){return console.log(res.msg);}
           let result = res.data;
-          commit(indexTypes.mutations.setProductTypes, result.pTypes);
-          commit(indexTypes.mutations.setNewsTypes, result.pTypes);
+          if(result.code !== rCode.OK){return console.log(result.msg);}
+          let data = result.data;
+          commit(indexTypes.mutations.setProductTypes, data.pType);
+          commit(indexTypes.mutations.setNewsTypes, data.nType);
         }
 
       },
+    },
+    getters: {
+      pTypes: state => state.pTypes,
+      nTypes: state => state.nTypes,
+      productTypes: state => {
+        let arr = state.pTypes;
+        return _transform(arr);
+      },
+      allNewsTypes: state => {
+        let arr = state.nTypes;
+        return _transform(arr);
+      },
+      solutionTypes: state => {
+        console.log(state.nTypes);
+        let arr = state.nTypes.filter(item =>
+          item.parent_type === dbField_esm.db_base.newsType.solution);
+        return _transform(arr);
+      },
+      newsTypes: state => {
+        let arr = state.nTypes.filter(item =>
+          item.parent_type === dbField_esm.db_base.newsType.news);
+        return _transform(arr);
+      },
+
     }
   },
   login

+ 0 - 6
store/indexStoreTypes.js

@@ -1,6 +0,0 @@
-export const login_types = {
-    mutations: {
-      setProductTypes: 'setProductTypes',
-      setNewsTypes: 'setNewsTypes',
-    }
-}

+ 30 - 2
until/fieldIsAllow.js

@@ -52,11 +52,16 @@ const hrefRule = [
     },
     {
         type: 'string',
-        regex: /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/,
+        // 是否符合url地址,支持域名与ip/^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/
+        regex: /(https?|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/,
         message: '链接格式不正确'
     },
 ];
 
+const requireIdRule = [
+  requiredRuleItem,
+]
+
 let checkCode = function (val) {
     let p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
     let factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
@@ -153,6 +158,10 @@ const paramsRules = [
     {
         keys: ['href'],
         rules: hrefRule,
+    },
+    {
+      keys: [/id/gi,'fileData'],
+      rules: requireIdRule
     }
 ]
 
@@ -170,7 +179,26 @@ let code_pass = 1,
 
 function _c(key,value){
     // 查找对应规则
-    let _obj = paramsRules.find(item=>item.keys.includes(key));
+    let _obj = paramsRules.find(item=>{
+      // 判断是否为正则
+      for (const _matchKey of item.keys) {
+        // 判断是否为正则
+        if(_matchKey instanceof RegExp){
+          // console.log(`使用正则进行匹配,${_matchKey.test(key)}`);
+          if(_matchKey.test(key)){
+            // console.log(`通过正则匹配规则成功,${_matchKey.test(key)}`);
+            return true;
+          }
+        }else{
+          // console.log(`比较是否全等,${_matchKey} === ${key} ?${_matchKey === key}`);
+          if(_matchKey === key){
+            // console.log(`通过字符${_matchKey}匹配成功`);
+            return true;
+          };
+        }
+      }
+      return false;
+    });
     console.log(_obj)
     if(!_obj||!_obj.rules){
         return [code_notMatch];