소스 검색

change: 轮播管理功能完成
next: 前端动态获取轮播数据

kindring 2 년 전
부모
커밋
06bbfdf896

+ 7 - 3
components/search/searchBox.vue

@@ -128,10 +128,14 @@ export default {
       console.log(page);
       // 加载数据
       if(page < this.page){
-        return console.log(`不加载数据`)
+        console.log(`不加载数据`);
+      }else{
+        await this.loadData(page + 1);
       }
-      await this.loadData(page + 1);
-      if(index + this.limit > this.total){
+
+      console.log(`检测是否加载数据 total: ${this.total} <=
+      limit: ${this.limit} + index: ${index}  ===>  ${this.total <= this.limit + index}`)
+      if(this.total <= this.limit + index){
         console.log(`同时获取下一页数据`);
         await this.loadData(page + 2);
       }

+ 9 - 0
map/apiMap.js

@@ -50,8 +50,17 @@ export const apiMap = {
   carouselList: {
     path: `/api/base/carousel`
   },
+  carouselAllList: {
+    path: `/api/base/carousel/list`
+  },
   baseTypes: {
     path: `/api/base/types`
+  },
+  baseAddCarousel: {
+    path: `/api/base/carousel`
+  },
+  baseUpdateCarousel: {
+    path: `/api/base/carousel`
   }
 }
 

+ 5 - 0
map/dbField_esm.js

@@ -30,6 +30,11 @@ export const db_base = {
     news: 2,
     page: 3,
   },
+  // 轮播状态
+  carouselState: {
+    disable: '0',
+    enable: '1',
+  },
   // 文章类型分类
   newsType: {
     all: -1,

+ 166 - 18
pages/manger/index/carousel.vue

@@ -15,6 +15,8 @@ import {apiMap} from "../../../map/apiMap";
 import SearchBox from "../../../components/search/searchBox.vue";
 import {pTypes} from "../../../map/productMap";
 import {newsType} from "../../../map/newMap";
+import {toNumber} from "../../../until/typeTool";
+import {isEmpty} from "../../../server/tools/typeTool_cjs";
 export default defineComponent({
   name: 'carousel',
   computed: {
@@ -69,11 +71,15 @@ export default defineComponent({
           state: 0,
         },
         // 状态 0:禁用,1:启用
-        status: {
-          val: 0,
-          init: 0,
+        state: {
+          val: dbField_esm.db_base.carouselState.disable,
+          init: dbField_esm.db_base.carouselState.disable,
           msg: '',
           state: 0,
+          options: [
+            {label: '禁用', value: dbField_esm.db_base.carouselState.disable},
+            {label: '启用', value: dbField_esm.db_base.carouselState.enable},
+          ]
         },
         // 轮播类型 '0:product','1:news','2:page','3:href'
         type: {
@@ -141,7 +147,7 @@ export default defineComponent({
   methods: {
     async getCarouselList(){
       this.loading = true;
-      let [err,res] = await handle(this.$axios.get(apiMap.carouselList.path));
+      let [err,res] = await handle(this.$axios.get(apiMap.carouselAllList.path));
       this.loading = false;
       if(err){
         if(this.NotificationKey){
@@ -249,6 +255,7 @@ export default defineComponent({
         return [{message:result.msg},null];
       }
     },
+
     checkFormItem(field,enumOptions,reCheckField){
       let formItem = this.form[field];
       if (formItem){
@@ -359,26 +366,115 @@ export default defineComponent({
     onPopOkClickHandle(){
       if(this.isEditCarousel){
         console.log('保存修改后的轮播数据');
+        this.updateCarouselExecute();
       }else{
         console.log('新增轮播图');
         this.addCarouselExecute();
       }
     },
-    addCarouselExecute(){
+    async addCarouselExecute(){
       // 生成新数据表单
       let carouselData = {};
       let isPass = this.checkFormItem();
       if(!isPass){
         return console.log('数据验证不通过');
       }
+      console.log('开始生成新数据表单');
+      carouselData.sort = this.form.sort.val;
+      carouselData.type = this.form.type.val;
+      carouselData.value = this.form.value.val;
+      carouselData.fileId = this.form.fileData.val;
+      carouselData.state = this.form.state.val;
+      // 生成新数据表单完毕
+      console.log('生成新数据表单完毕');
+      this.carouselPopLoading = true;
+      let [err,res] = await handle(this.$axios.put(apiMap.baseAddCarousel.path,carouselData));
+      this.carouselPopLoading = false;
+      if(err){
+        console.log(err);
+        return this.$message.error('新增轮播图失败');
+      }
+      this.$message.success('新增轮播成功');
+      this.carouselPopShow = false;
+      await this.getCarouselList();
 
     },
+    async updateCarouselExecute(){
+      let carouselData = {};
+      let isPass = this.checkFormItem();
+      if(!isPass){
+        return console.log('数据验证不通过');
+      }
+      // 获取更新项
+      console.log(`获取更新项`);
+      let updateItems = {};
+      console.log(this.carouselData);
+      let carouselId = this.carouselData.id;
+      if(this.form.sort.val != toNumber(this.carouselData.sort)){
+        updateItems.sort = this.form.sort.val;
+      }
+      if(this.form.type.val != toNumber(this.carouselData.type)){
+        updateItems.type = this.form.type.val;
+      }
+      if(this.form.value.val != this.carouselData.value){
+        updateItems.value = this.form.value.val;
+      }
+      if(toNumber(this.form.fileData.val) != this.carouselData.fileId){
+        updateItems.fileId = this.form.fileData.val;
+      }
+      if(this.form.state.val != this.carouselData.state){
+        updateItems.state = this.form.state.val;
+      }
+      if(isEmpty(updateItems)){
+        return this.$message.warn('未修改任何数据');
+      }
+      console.log(`更新轮播数据,更新数量: ${Object.keys(updateItems).length} 更新字段: [${Object.keys(updateItems).join(',')}]`);
+      this.carouselPopLoading = true;
+      let [err,res] = await handle(this.$axios.post(apiMap.baseUpdateCarousel.path,{
+        carouselId,
+        updateItems
+      }));
+      this.carouselPopLoading = false;
+      if(err){
+        console.log(err);
+        return this.$message.error('更新轮播图失败');
+      }
+      let  result = res.data;
+      if (result.code === rCode.OK){
+        this.$message.success('更新轮播成功');
+        this.carouselPopShow = false;
+        await this.getCarouselList();
+      }else{
+        this.$message.error(`更新轮播失败,${result.msg}`);
+      }
 
+    },
 
-
-    showPop(){
-      this.popShow = true;
-      this.popLoading = false;
+    getCarouselTypeText(type){
+      type = toNumber(type);
+      let typeText = '';
+      if(type === dbField_esm.db_base.carouselType.production){
+        typeText = '产品';
+      }else if(type === dbField_esm.db_base.carouselType.news){
+        typeText = '文章';
+      }else if(type === dbField_esm.db_base.carouselType.href){
+        typeText = '直接链接';
+      }else{
+        typeText = '暂未支持类型';
+      }
+      return typeText
+    },
+    getCarouselStateText(state){
+      // state = toNumber(state);
+      let typeText = '';
+      if(state === dbField_esm.db_base.carouselState.enable){
+        typeText = '启用';
+      }else if(state === dbField_esm.db_base.carouselState.disable){
+        typeText = '禁用';
+      }else{
+        typeText = '未知状态';
+      }
+      return typeText
     },
     cancelPop(){
       this.imageSelectVisible = false;
@@ -388,7 +484,7 @@ export default defineComponent({
       console.log(fileItem);
       this.cancelPop();
       this.$nextTick(()=>{
-        this.form.fileData.val = fileItem.filePath;
+        this.form.fileData.val = fileItem.fileId;
         this.form.fileData.state = 1;
         this.form.fileData.msg = '';
         this.form.fileData.showText = fileItem.filePath;
@@ -419,6 +515,34 @@ export default defineComponent({
       console.log(e);
       console.log(this.productSearch.type.val);
     },
+    onClickEditHandle(item){
+      console.log(`点击编辑轮播图`);
+      console.log(item);
+      if(!item || !item.id){
+        return this.$message.warn('轮播数据获取异常,已经取消编辑');
+      }
+      this.initCarouseForm();
+
+      this.isEditCarousel = true;
+      this.carouselData = item;
+      this.carouselPopShow = true;
+      this.carouselPopLoading = true;
+      this.form.sort.val = toNumber(item.sort);
+      this.form.sort.init = toNumber(item.sort);
+      this.form.type.val = toNumber(item.type);
+      this.form.type.init = toNumber(item.type);
+      this.form.value.val = item.value;
+      this.form.value.init = item.value;
+      this.form.value.showText = item.valueShowText;
+      this.form.value.oldShowText = item.oldShowText;
+      this.form.fileData.val = item.fileId;
+      this.form.fileData.init = item.fileId;
+      this.form.fileData.showText = item.filePath;
+      this.form.fileData.oldShowText = item.filePath;
+      this.form.state.val = item.state;
+      this.carouselPopLoading = false;
+
+    }
 
   },
 
@@ -433,11 +557,16 @@ export default defineComponent({
   <div class="mt-2 rounded bg-white p-2">
     <div class="py-1 border-b border-cyan-300 flex justify-between">
         点击下方快进行管理轮播图数据,一次性不要添加过多轮播图
-<!--      新增按钮-->
-      <a-button type="primary" class="ant-icon-btn" icon="plus" @click="openAddCarouselModal" :loading="loading"></a-button>
-<!--      刷新按钮-->
-      <a-button type="primary" class="ant-icon-btn" icon="reload" @click="getCarouselList" :loading="loading"></a-button>
+      <div class="px-2 flex">
+
+        <!--      新增按钮-->
+        <a-button type="primary" class="ant-icon-btn mr-2" icon="plus" @click="openAddCarouselModal" :loading="loading"></a-button>
+        <!--      刷新按钮-->
+        <a-button type="primary" class="ant-icon-btn " icon="reload" @click="getCarouselList" :loading="loading"></a-button>
+
+      </div>
     </div>
+
     <div class="w-full h-auto transition">
       <div v-show="loading" class="w-full h-64 flex justify-center items-center ">
         <a-spin size="large" />
@@ -452,9 +581,17 @@ export default defineComponent({
           <image-viewer :src="item.filePath"></image-viewer>
         </div>
         <div class="w-1/2 h-full box-border pl-2">
-          <a-button @click="showPop">编辑</a-button>
-          排序{{item.sort}},数字越小越靠前
-          链接地址: {{item.href}}
+          <div class="w-full py-2 border-bottom border-gray-400">
+            排序: {{item.sort}}
+          </div>
+          <div class="w-full py-2 border-bottom border-gray-400">
+            {{getCarouselTypeText(item.type)}}: {{item.valueShowText}}
+          </div>
+          <div class="w-full py-2 border-bottom border-gray-400">
+            状态: {{getCarouselStateText(item.state)}}
+          </div>
+          <a-button @click="onClickEditHandle(item)">编辑</a-button>
+
         </div>
 
       </div>
@@ -482,6 +619,17 @@ export default defineComponent({
            />
          </input-row>
 
+        <input-row :msg="form.state.msg"
+                    label="状态">
+            <a-radio-group v-model="form.state.val">
+              <a-radio-button v-for="opt in form.state.options"
+                              :key="'cState'+opt.value"
+                              :value="opt.value">
+                {{ opt.label }}
+              </a-radio-button>
+            </a-radio-group>
+        </input-row>
+
 <!--          轮播类型选择 -->
           <input-row :msg="form.type.msg"
                       label="轮播类型">
@@ -569,7 +717,7 @@ export default defineComponent({
               </search-box>
             </div>
             <a-button type="primary">
-              选择产品
+              选择文章
             </a-button>
           </a-popover>
         </input-row>

+ 110 - 7
server/control/c_base.js

@@ -5,7 +5,7 @@ const d_news = require("../database/d_news");
 const codeMap = require("../map/rcodeMap");
 const dbField = require("../map/dbField");
 const {searchHandle} = require("../tools/searchSql");
-const {isEmpty} = require("../tools/typeTool_cjs");
+const {isEmpty, toNumber} = require("../tools/typeTool_cjs");
 const config_path = require("../configs/path");
 const {isArray} = require("ant-design-vue/lib/_util/vue-types/utils");
 const {mvFile, rmFile} = require("../tools/saveFiles_cjs");
@@ -13,7 +13,25 @@ const {getUnixTimeStamp} = require("../tools/time_cjs");
 const {filePathToUrl} = require("../tools/filePathTool");
 const log = require("../logger").logger("c_base","info");
 
-async function getCarousel(){
+// 获取启用的轮播列表
+async function getEnableCarousel(){
+  let err,res;
+  [err,res] = await handle(d_base.getCarousel({
+    state: dbField.db_base.carouselState.enable
+  }));
+  // console.log(res);
+  if(err){
+    return [err,null];
+  }
+  // 路径转换
+  res = res.map(item=>{
+    item.filePath = filePathToUrl(item.fileType,item.filePath);
+    return item;
+  });
+  return [null,res];
+}
+
+async function getAllCarousel(){
   let err,res;
   [err,res] = await handle(d_base.getCarousel());
   // console.log(res);
@@ -35,8 +53,7 @@ async function addCarousel(sort,fileId,type,value){
   let updateTime = getUnixTimeStamp();
   // 根据type判断value
   if(type !== dbField.db_base.carouselType.href){
-    if(type === dbField.db_base.carouselType.product){
-      // 获取产品信息
+    if(type === dbField.db_base.carouselType.production){
       [err,res] = await handle(d_product.getProductById(value));
     }else if(type === dbField.db_base.carouselType.news){
       // 获取新闻信息
@@ -74,11 +91,93 @@ async function deleteCarousel(id){
   return [null,res];
 }
 
-async function updateCarousel(id,updateParam){
+async function updateCarousel(id,updateItems){
   let err,res;
+  let rawData = {};
+  let unixTime = getUnixTimeStamp();
+  let updateData = {};
+  let typeKeys = Object.keys(dbField.db_base.carouselType);
+  let typeString = '';
+  let typeShowText = '';
+  // 判断是否需要更新type
+  if (updateItems.value){
+    // 获取基础type值
+    if(!isEmpty(updateItems.type)){
+      typeString = updateItems.type;
+      updateData.type = updateItems.type;
+    }else{
+      [err,res] = await handle(d_base.getCarouselById(id));
+      if(err){
+        log.error(`[修改轮播] 获取轮播基础数据时异常 ${err.message}`);
+        return [{eCode: codeMap.ServerError, eMsg: `获取轮播基础数据异常`},null];
+      }
+      if(isEmpty(res)){
+        log.info(`[修改轮播] 无法通过id找到轮播数据`);
+        return [{eCode: codeMap.NotFound, eMsg: `请检测id是否正确`},null];
+      }
+      rawData = res[0];
+      typeString = rawData.type;
+    }
+
+    // 需要更新具体值
+    if(typeString !== dbField.db_base.carouselType.href){
+      if(updateItems.type === dbField.db_base.carouselType.production){
+        typeShowText = '产品';
+        // 获取产品信息
+        [err,res] = await handle(d_product.getProductById(updateItems.value));
+      }else if(typeString === dbField.db_base.carouselType.news){
+        typeShowText = '文章';
+        // 获取新闻信息
+        [err,res] = await handle(d_news.getNewsById(updateItems.value));
+      }else {
+        return [{eCode: codeMap.NotParam, eMsg: `轮播类型异常!`},null];
+      }
+      if(err){
+        console.log(err);
+        log.error(`[修改轮播] 检索${typeShowText}信息失败 ${err.message}}`);
+        return [{eCode: codeMap.ServerError, eMsg: `检索${typeShowText}数据异常`},null];
+      }
+      if(isEmpty(res)){
+        log.info(`[修改轮播] 无法找到对应的${typeShowText}数据`);
+        return [{eCode: codeMap.NotFound, eMsg: `无法找到对应的产品或者文章信息`},null];
+      }
+      updateData.valueShowText = res[0].title;
+    }
+
+    updateData.value = updateItems.value;
+  }
+
+  if (!isEmpty(updateItems.sort)){
+    updateData.sort = toNumber(updateItems.sort);
+  }
+
+  if (!isEmpty(updateItems.state)){
+    updateData.state = updateItems.state;
+  }
+
+  if(updateItems.fileId){
+    updateData.fileId = updateItems.fileId;
+    // todo 检测文件id是否存在
+  }
+  console.log(updateData);
+  [err,res] = await handle(d_base.updateCarousel(id,updateData,unixTime));
+  if(err){
+    console.log(err);
+    log.error(`[修改轮播] 数据更新失败,${err.message}`);
+    return [{eCode: codeMap.SaveError, eMsg: `数据更新失败,请稍后重试`},null];
+  }
   return [null,res];
 }
 
+async function deleteFile(id){
+  let err,res;
+  [err,res] = await handle(d_base.deleteFile(id));
+  if(err){
+    log.error(`[删除文件] 删除数据异常 ${err.message}`);
+    return [err,null];
+  }
+  return [null,res];
+}
 
 /**
  * 文件上传
@@ -222,12 +321,16 @@ async function getTypes(){
   return [null,types];
 }
 module.exports = {
-  getCarousel,
+  getEnableCarousel,
+  getAllCarousel,
+  addCarousel,
+  deleteCarousel,
+  updateCarousel,
   uploadFile,
   searchFiles,
   deleteFile,
   getTypes,
-  addCarousel
+
 }
 
 

+ 23 - 1
server/control/c_news.js

@@ -4,6 +4,7 @@ const codeMap = require("../map/rcodeMap");
 const log = require("../logger").logger("c_solution","info");
 
 const d_news = require("../database/d_news");
+const d_product = require("../database/d_product");
 
 async function addReadNum(newId){
   let [err,res] = await handle(d_news.addReadNum(newId));
@@ -13,6 +14,27 @@ async function addReadNum(newId){
   return [null,'ok'];
 }
 
+async function searchNewsByMini(type, key, p, l){
+  p = p || 1;
+  l = l || 10;
+  let _params = {
+  }
+  if(type !== 'all'){
+    _params.type = type;
+  }
+  if(key){
+    _params.key = key
+  }
+
+  return await searchHandle(
+    '搜索文章失败',
+    d_news.searchAllNewsMini,
+    _params,
+    p,
+    l);
+}
+
 module.exports = {
-  addReadNum
+  addReadNum,
+  searchNewsByMini
 }

+ 57 - 3
server/database/d_base.js

@@ -16,21 +16,72 @@ const log = require("../logger").logger("d_base","info");
  * 获取轮播图
  * @returns {Promise | Promise<unknown>}
  */
-function getCarousel(){
+function getCarousel(searchParam = {}){
   let sql = `SELECT c.*,f.filePath,f.fileType,f.fileId
             FROM
                 hfy_carousel as c,
                 hfy_files as f
             WHERE c.fileId = f.fileId`;
-  return mysql.pq(sql);
+  let values = [];
+  if(!isEmpty(searchParam.state)){
+    sql += ` and c.state = ?`;
+    values.push(searchParam.state);
+  }
+  return mysql.pq(sql,values);
 }
 
+
+function getCarouselById(id){
+  let sql = `SELECT c.*,f.filePath,f.fileType,f.fileId
+            FROM
+                hfy_carousel as c,
+                hfy_files as f
+            WHERE
+                c.fileId = f.fileId
+                c.id = ?
+            `;
+  let values = [id];
+  return mysql.pq(sql,values);
+}
 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 updateCarousel(id,updateParam,time){
+  let sql = `UPDATE hfy_carousel SET `;
+  let values = [];
+  if(!isEmpty(updateParam.sort)){
+    sql += ` sort = ?,`;
+    values.push(updateParam.sort);
+  }
+  if(updateParam.fileId){
+    sql += ` fileId = ?,`;
+    values.push(updateParam.fileId);
+  }
+  if(!isEmpty(updateParam.type)){
+    sql += ` type = ?,`;
+    values.push(updateParam.type);
+  }
+  if(updateParam.value && updateParam.valueShowText){
+    sql += ` value = ?,`;
+    values.push(updateParam.value);
+    sql += ` valueShowText = ?,`;
+    values.push(updateParam.valueShowText);
+  }
+  if(!isEmpty(updateParam.state)){
+    sql += ` state = ?,`;
+    values.push(updateParam.state);
+  }
+  sql += ` updateTime = ?`;
+  values.push(time);
+  sql += ` WHERE id = ? limit 1`;
+  values.push(id);
+  console.log(sql);
+  console.log(values);
+  return mysql.pq(sql,values);
+}
 function uploadFiles(type,fileNameArr,uploadTime){
   let sql = `INSERT INTO hfy_files (fileType, filePath, uploadTime)
                     VALUES ${fileNameArr.map(f=>`(?,?,?)`).join(',')}`;
@@ -89,9 +140,12 @@ function deleteFile(fileId){
 }
 module.exports = {
   getCarousel,
+  getCarouselById,
+  addCarousel,
+  updateCarousel,
   uploadFiles,
   loadFiles,
   getFileById,
   deleteFile,
-  addCarousel
+
 }

+ 1 - 1
server/database/d_news.js

@@ -43,7 +43,7 @@ function searchAllNewsMini(type='array',searchParam,page,limit){
 }
 
 function getNewsById(id){
-  let sql = `SELECT * FROM hfy_product WHERE id = ? limit 1`;
+  let sql = `SELECT * FROM hfy_news WHERE id = ? limit 1`;
   return mysql.pq(sql,[id]);
 }
 

+ 4 - 0
server/map/dbField.js

@@ -27,6 +27,10 @@ const db_base = {
     news: 2,
     page: 3,
   },
+  carouselState: {
+    disable: '0',
+    enable: '1',
+  },
   // 文章类型分类
   newsType: {
     all: -1,

+ 44 - 7
server/router/r_base.js

@@ -6,7 +6,7 @@ const decode = require("../tools/decode_cjs");
 const time = require("../tools/time_cjs");
 const {toSqlString} = require("../tools/searchSql");
 const progressField = require('../map/progressField');
-const {isEmpty} = require("../tools/typeTool_cjs");
+const {isEmpty, toNumber} = require("../tools/typeTool_cjs");
 const checkLogin = require("../middleware/checkSession");
 const upload = require("../middleware/upload");
 const config_path = require("../configs/path");
@@ -14,14 +14,27 @@ const log = require("../logger").logger("r_base","info");
 
 router.get('/carousel', async (req, res) => {
   try{
-    let [err, data] = await c.getCarousel();
+    let [err, data] = await c.getEnableCarousel();
     if(err){
-      controlError(res, err,`获取轮播图失败 ${err.eMsg||err.message}`);
+      controlError(res, err,`获取启用的轮播图失败 ${err.eMsg||err.message}`);
     }else{
       success(res, data);
     }
   }catch (e){
-    ServerError(res, e, `获取轮播图失败 ${e.message}`);
+    ServerError(res, e, `获取启用轮播图失败 ${e.message}`);
+  }
+});
+
+router.get('/carousel/list', async (req, res) => {
+  try{
+    let [err, data] = await c.getAllCarousel();
+    if(err){
+      controlError(res, err,`获取所有轮播图失败 ${err.eMsg||err.message}`);
+    }else{
+      success(res, data);
+    }
+  }catch (e){
+    ServerError(res, e, `获取所有轮播图失败 ${e.message}`);
   }
 });
 
@@ -50,13 +63,15 @@ router.post('/carousel', checkLogin(progressField.session_hfy), async (req, res)
   try{
     log.info(`[轮播图修改] 开始修改轮播图数据`);
     // 获取轮播数据
-    let {carouselId,changeParams} = req.body;
+    let {carouselId,updateItems} = req.body;
     let err,data;
+    console.log(carouselId);
+    console.log(updateItems);
     // 检测参数
-    if(isEmpty(carouselId) || isEmpty(changeParams) ){
+    if(isEmpty(carouselId) || isEmpty(updateItems) ){
       return paramFail(res, '缺少必要参数');
     }
-    [err,data] = await c.changeCarousel(carouselId,changeParams);
+    [err,data] = await c.updateCarousel(carouselId,updateItems);
     if(err){
       controlError(res, err,`轮播图修改 ${err.eMsg||err.message}`);
     }else{
@@ -67,6 +82,28 @@ router.post('/carousel', checkLogin(progressField.session_hfy), async (req, res)
   }
 });
 
+router.delete('/carousel/:carouselId', checkLogin(progressField.session_hfy), async (req, res) => {
+  try{
+    log.info(`[删除轮播] 开始删除轮播图数据`);
+    // 获取轮播数据
+    let {carouselId} = req.params;
+    let err,data;
+    // 检测参数
+    carouselId = toNumber(carouselId);
+    if(carouselId < 1){
+      return paramFail(res, '参数异常,请检查参数');
+    }
+    [err,data] = await c.deleteCarousel(carouselId);
+    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;

+ 26 - 0
server/router/r_news.js

@@ -30,6 +30,32 @@ router.get(
     }
 });
 
+router.get('/mini', async (req, res) => {
+  try{
+    log.info(`[搜索文章] 只获取基础值`)
+    let err, result;
+    let {key, l, p, type} = req.query;
+    type = type || 'all';
+    l = typeTool.toNumber(l);
+    p = typeTool.toNumber(p);
+    log.info(`page=${p},limit=${l}`);
+    [err, result] = await c.searchNewsByMini(type, key, p, l);
+    if(err){
+      log.info(`[搜索文章] err=${err}`);
+      return controlError(res, err, null);}
+    log.info(`result len=${result.arr.length}`)
+    searchSuccess(res,
+      result.arr,
+      result.total,
+      result.page,
+      result.limit,
+    );
+  }catch (e) {
+    ServerError(res, null, e.message);
+  }
+});
+
+
 router.get('/read',async(req,res)=>{
   try{
     let err, result;

+ 1 - 3
server/tools/typeTool_cjs.js

@@ -57,7 +57,7 @@ function isEmpty(v){
     }else if(isObject(v)){
         return Object.keys(v).length === 0
     }else if(v === 0){
-        return true;
+        return false;
     }else{
         return !v
     }
@@ -65,8 +65,6 @@ function isEmpty(v){
 
 // 判断数据是否存在,不允许为空字符串,空对象与空数组, 允许为 0
 
-
-
 module.exports = {
     toNumber,
     toString,