Parcourir la source

change: 修改页面逻辑,轮播获取接口

kindring il y a 2 ans
Parent
commit
83a76edde4

+ 27 - 4
components/banner/banner.vue

@@ -10,9 +10,10 @@
             'banner-show-now':i===bannerIndex
           }"
         v-show="i===bannerIndex"
+        @click="onClickBanner(item)"
     >
       <!--        图片框-->
-      <img :src="item.img" :alt="item.title">
+      <img :src="item.filePath" :alt="item.title">
       <!--        文本框-->
       <div class="w-p1200 h-full py-2 border-box relative" v-show="showText">
         <div class="view-text">
@@ -44,14 +45,18 @@
 </template>
 
 <script>
+import dbField_esm from "../../map/dbField_esm";
+import {toNumber} from "../../until/typeTool";
+
 export default {
   name: "banner",
   props: {
-    waitTime: {default:5000}
+    waitTime: {default:5000},
+    banners: {default:()=>[]},
   },
   data(){
     return {
-      banners:[{
+      bannerList:[{
         id: '1',
         url:'#/recommends',
         title: 'text',
@@ -82,7 +87,8 @@ export default {
       // 比例
     }
 },mounted() {
-    this.cursor()
+    console.log(this.banners);
+    this.cursor();
   },
   directives: {
     // 为元素设定比例
@@ -117,6 +123,23 @@ export default {
     changeBanner(i){
       this.bannerIndex = i;
       this.cursor();
+    },
+    onClickBanner(item){
+      // 根据轮播类型进行跳转
+      let url = '';
+      console.log(item);
+      if(toNumber(item.type) === dbField_esm.db_base.carouselType.href){
+        url = item.value;
+      }else if(toNumber(item.type) === dbField_esm.db_base.carouselType.production){
+        url = `/product/info?id=${item.value}`;
+      }else if(toNumber(item.type) === dbField_esm.db_base.carouselType.production){
+        url = `/solution/info?id=${item.value}`;
+      }
+      console.log(url);
+      if(url){
+        // 直接跳转至url中
+        window.location.href = url;
+      }
     }
   }
 }

+ 1 - 1
components/layout/adminLayout.vue

@@ -171,7 +171,7 @@ export default {
 <!--          侧边栏,带标题,icon,下拉菜单-->
       <div v-for="(item,i) in sideMenus"
            :key="'sideBar-'+i"
-           :class="`bar-menu-item ${item.isShow?'bar-menu-item-show':''}`"
+           :class="`bar-menu-item ${item.isShow?'bar-menu-info-show':''}`"
       >
         <div class="menu-title">
           <span class="icon"> <svg-icon :icon-class="item.icon"/> </span>

+ 2 - 2
components/newCenter.vue

@@ -83,14 +83,14 @@ export default {
           title: "ETC停车场的发展前景",
           type: 3,
           description: "1.无需人值守降低人工成本;2.非现金支付,杜绝跑冒滴漏;3.集中式管理,财务一目了然;4.无缝对接各类基于ETC的应用系统;5.兼容全国高速公路,ETC收费系统;6.不停车通行,提升通行效率;",
-          src: '/news/item/pa?id=47',
+          src: '/news/info/pa?id=47',
           time: '2022-09-20'
         },{
           key: 'five',
           title: "森林防火4G摄像机视频监控解决方案",
           type: 1,
           description: "采用4G摄像机4G高清网络摄像机或4G高清视频服务器+摄像头组合,将监控点附近的相关视频实时回传至监控中心,林区负责人或监管部门可实时了解林区状态,如有隐患或火灾,可第一时间发现并采取相应措施。\n" ,
-          src: '/solution/item/sol?id=49',
+          src: '/solution/info/sol?id=49',
           time: '2022-01-02'
         }
       ]

+ 1 - 1
components/productList.vue

@@ -58,7 +58,7 @@ export default {
       if(product.sourceType === "1"){
         url = product.source;
       }else{
-        url = `/product/item/${product.type_key}?id=${product.id}`
+        url = `/product/info/${product.type_key}?id=${product.id}`
       }
       window.location.href = url;
     }

+ 1 - 1
components/search/searchBox.vue

@@ -97,7 +97,7 @@ export default {
         let item = res.data[n];
         if(item){
           // 时间字段转换
-          // item.subTitle = time.dateFormat(time.timeStamp_to_Date(item.loginTime),'YY-MM-DD H:m:s');
+          // info.subTitle = time.dateFormat(time.timeStamp_to_Date(info.loginTime),'YY-MM-DD H:m:s');
           // 展示字段转换
           item['innerText'] = item.showText.replace(key,`<span style="color:red;">${key}</span>`);
         }

+ 1 - 1
components/solutionList.vue

@@ -62,7 +62,7 @@ export default {
       if(solution.sourceType === "1"){
         url = solution.source;
       }else{
-        url = `/${this.parentType}/item/${solution.type_key}?id=${solution.id}`
+        url = `/${this.parentType}/info/${solution.type_key}?id=${solution.id}`
       }
       window.location.href = url;
     }

+ 2 - 2
map/apiMap.js

@@ -53,8 +53,8 @@ export const apiMap = {
   carouselAllList: {
     path: `/api/base/carousel/list`
   },
-  baseTypes: {
-    path: `/api/base/types`
+  baseDatas: {
+    path: `/api/base/base`
   },
   baseAddCarousel: {
     path: `/api/base/carousel`

+ 11 - 11
nuxt.config.js

@@ -118,23 +118,23 @@ export default {
           '/product/sm',
           '/product/low',
           '/product/cam',
-          '/product/item/m2m',
-          '/product/item/aiCam',
-          '/product/item/sm',
-          '/product/item/low',
-          '/product/item/cam',
+          '/product/info/m2m',
+          '/product/info/aiCam',
+          '/product/info/sm',
+          '/product/info/low',
+          '/product/info/cam',
           '/solution/sol',
           '/solution/acs',
           '/solution/epower',
-          '/solution/item/sol',
-          '/solution/item/acs',
-          '/solution/item/epower',
+          '/solution/info/sol',
+          '/solution/info/acs',
+          '/solution/info/epower',
           '/news/com',
           '/news/pa',
           '/news/in',
-          '/news/item/com',
-          '/news/item/pa',
-          '/news/item/in',
+          '/news/info/com',
+          '/news/info/pa',
+          '/news/info/in',
         ]
     }
 }

+ 7 - 1
pages/index.vue

@@ -2,7 +2,7 @@
   <div class="w-screen pad:w-full bg-amber-200 relative">
 <!--    header 部分布局-->
     <lucency-header :lang="lang" page-key="index" :is-phone="isPhone" />
-    <banner :wait-time="2500"/>
+    <banner :banners="carousel" :wait-time="2500"/>
     <new-center v-if="isPhone" :lang="lang"/>
     <product-center v-if="isPhone" :lang="lang"/>
 <!--    优势项目部分展示,参考海康-->
@@ -41,6 +41,12 @@ export default {
     this.$root.$on('changeLang',this.switchLang)
     this.isPhone = isMediaView(0,1024);
   },
+  computed:{
+    carousel(){
+      // url转换
+      return this.$store.state.index.carousel;
+    },
+  },
   methods:{
     switchLang(nextLang){
       // console.log("11111111111111111")

+ 3 - 3
pages/manger/index.vue

@@ -73,9 +73,9 @@ export default {
       {{ userInfo.name }} <a-icon type="down" />
     </a>
     <a-menu slot="overlay">
-<!--      <a-menu-item key="1">-->
-<!--        <a href="#">1st menu item</a>-->
-<!--      </a-menu-item>-->
+<!--      <a-menu-info key="1">-->
+<!--        <a href="#">1st menu info</a>-->
+<!--      </a-menu-info>-->
       <a-menu-item key="3">
         <span @click="logout">退出登录</span>
       </a-menu-item>

+ 1 - 2
pages/manger/index/carousel.vue

@@ -15,8 +15,7 @@ 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";
+import {toNumber,isEmpty} from "../../../until/typeTool";
 export default defineComponent({
   name: 'carousel',
   computed: {

+ 2 - 2
pages/news/item/_type.vue → pages/news/info/_type.vue

@@ -1,10 +1,10 @@
 <template>
-<!--  <item-index :p-type="type" />-->
+<!--  <info-index :p-type="type" />-->
   <item-index :p-type="type" :p-info="solutionInfo" :p-id="pId"></item-index>
 </template>
 
 <script>
-import ItemIndex from "~/pages/news/item/index";
+import ItemIndex from "~/pages/news/info/index";
 import {apiMap, baseUrl} from "~/map/apiMap";
 import {toNumber} from "~/until/typeTool";
 import handle from "~/until/handle";

+ 36 - 2
pages/news/item/index.vue → pages/news/info/index.vue

@@ -37,11 +37,37 @@ import BigTitle from "~/components/public/bigTitle.vue";
 import LucencyHeader from "~/components/header/lucencyHeader.vue";
 import ItemBanner from "~/components/banner/itemBanner.vue";
 import {apiMap, baseUrl} from "~/map/apiMap";
+import {toNumber,isEmpty} from "../../../until/typeTool";
 
 export default {
   name: "newsItemIndex",
   props:['uLang','pType', 'pInfo', "pId"],
   components:{ItemBanner, LucencyHeader, BigTitle, defaultFooter},
+  async asyncData(ctx){
+    let err,res;
+    let id = ctx.query.id;
+    // id转数字
+    let url = baseUrl + apiMap.newsInfo.path ;
+    if(!toNumber(id)){ctx.redirect(`/news`);}
+    console.log(`开始获取文章 id:${id}`);
+    url += `/${id}`;
+    [err,res] = await handle(axios.get(url));
+    if(err){
+      // 加载失败,返回至产品页面
+      console.log(`查询数据失败`);
+      ctx.redirect(`/news`);
+      return {solutionId:id}
+    }
+    let result = res.data;
+    if(result.code === 1){
+      console.log(result.data);
+      return {solutionId:id, solutionDetail:result.data}
+    }else{
+      console.log(`查询数据失败,服务器异常`);
+      ctx.redirect(`/news`);
+    }
+    return {solutionId:id}
+  },
   data(){
     return {
       langType: langMap.lang,
@@ -56,8 +82,16 @@ export default {
   },
   beforeMount() {
     console.log(this.pInfo);
-    this.solutionDetail = this.pInfo;
-    this.solutionId = this.pId;
+    if(isEmpty(this.pInfo) && isEmpty(this.solutionDetail)){
+      console.log('无法获取文章数据');
+      this.$router.push('/news');
+    }
+    if(isEmpty(this.solutionDetail)){
+      this.solutionDetail = this.pInfo;
+    }
+    if(isEmpty(this.solutionId)){
+      this.solutionId = this.pId;
+    }
     this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
     this.solutionDetail.date_time  = timestampToTime(this.solutionDetail.date_time);
     this.timer = setTimeout(()=>{

+ 2 - 1
pages/product/item/_type.vue → pages/product/info/_type.vue

@@ -3,7 +3,7 @@
 </template>
 
 <script>
-import ItemIndex from "~/pages/product/item/index";
+import ItemIndex from "~/pages/product/info/index";
 import {apiMap, baseUrl} from "~/map/apiMap";
 import handle from "~/until/handle";
 import axios from "axios";
@@ -21,6 +21,7 @@ export default {
   async asyncData(ctx){
     let err,res;
     let id = ctx.query.id;
+    console.log( `产品页加载`)
     // id转数字
     let url = baseUrl + apiMap.productInfo.path ;
     if(!toNumber(id)){ctx.redirect(`/product`);}

+ 46 - 7
pages/product/item/index.vue → pages/product/info/index.vue

@@ -49,12 +49,43 @@ import ItemBanner from "../../../components/banner/itemBanner";
 import {isMediaView} from "@/until/mediaView";
 import {apiMap, baseUrl} from "~/map/apiMap";
 import BigTitle from "~/components/public/bigTitle.vue";
+import {toNumber,isEmpty} from "../../../until/typeTool";
 
 export default {
   name: "itemIndex",
   components: {BigTitle, ItemBanner, LucencyHeader, DefaultFooter, qTab},
   props:['uLang','pType', 'pInfo'],
-
+  async asyncData(ctx){
+    // 判断是否有id,如果有id则请求数据,否则则不请求数据
+    let err,res;
+    let id = ctx.query.id;
+    // id转数字
+    let url = baseUrl + apiMap.productInfo.path ;
+    if(!toNumber(id)){
+      return ctx.redirect(`/product`);
+    }
+    console.log(`开始获取产品 id:${id}`);
+    url += `/${id}`;
+    [err,res] = await handle(axios.get(url));
+    if(err){
+      // 加载失败,返回至产品页面
+      console.log(`查询产品数据失败`);
+      ctx.redirect(`/product`);
+      return {}
+    }
+    let result = res.data;
+    if(result.code === 1){
+      // console.log(result.data);
+      return {
+        productDetail:result.data,
+        type: result.data.type_key,
+      }
+    }else{
+      console.log(`查询产品数据失败,服务器异常`);
+      ctx.redirect(`/product`);
+    }
+    return {}
+  },
   data(){
     return {
       langType: langMap.lang,
@@ -70,16 +101,24 @@ export default {
   },
   beforeMount() {
     console.log(this.pInfo);
-    this.productDetail = this.pInfo;
-    console.log(this.productDetail.detail)
-    console.log(this.productDetail.image)
+    if(isEmpty(this.productDetail) && isEmpty(this.pInfo)){
+      console.log('没有数据');
+      return this.$router.push('/product');
+    }
+
+    if(isEmpty(this.productDetail)){
+      this.productDetail = this.pInfo;
+    }
     this.productDetail.detail = unescape(this.productDetail.detail);
   },
   mounted() {
-    console.log(this.pType);
-    console.log(this.type);
+    // console.log(this.pType);
+    // console.log(this.type);
     this.isPhone = isMediaView(0,1024);
-    this.type = this.pType;
+    if(!isEmpty(this.type)){
+      this.type = this.pType;
+    }
+
   },
   methods:{
     getLangText(str) {

+ 1 - 1
pages/solution/item/_type.vue → pages/solution/info/_type.vue

@@ -3,7 +3,7 @@
 </template>
 
 <script>
-import ItemIndex from "~/pages/solution/item/index";
+import ItemIndex from "~/pages/solution/info/index";
 import {apiMap, baseUrl} from "~/map/apiMap";
 import {toNumber} from "~/until/typeTool";
 import handle from "~/until/handle";

+ 39 - 2
pages/solution/item/index.vue → pages/solution/info/index.vue

@@ -36,11 +36,39 @@ import BigTitle from "~/components/public/bigTitle.vue";
 import ItemBanner from "~/components/banner/itemBanner.vue";
 import LucencyHeader from "~/components/header/lucencyHeader.vue";
 import {apiMap} from "~/map/apiMap";
+import {toNumber,isEmpty} from "../../../until/typeTool";
+import axios from "axios";
+import {baseUrl} from "../../../map/apiMap";
 
 export default {
   name: "solutionItemIndex",
   props:['uLang', 'pType', 'pInfo', "pId"],
   components:{LucencyHeader, ItemBanner, BigTitle, defaultFooter},
+  async asyncData(ctx){
+    let err,res;
+    let id = ctx.query.id;
+    // id转数字
+    let url = baseUrl + apiMap.newsInfo.path ;
+    if(!toNumber(id)){ctx.redirect(`/solution`);}
+    console.log(`开始获取文章 id:${id}`);
+    url += `/${id}`;
+    [err,res] = await handle(axios.get(url));
+    if(err){
+      // 加载失败,返回至产品页面
+      console.log(`查询文章数据失败`);
+      ctx.redirect(`/solution`);
+      return {solutionId:id}
+    }
+    let result = res.data;
+    if(result.code === 1){
+      console.log(result.data);
+      return {solutionId:id, solutionDetail:result.data}
+    }else{
+      console.log(`查询文章数据失败,服务器异常`);
+      ctx.redirect(`/solution`);
+    }
+    return {solutionId:id}
+  },
   data(){
     return {
       langType: langMap.lang,
@@ -55,8 +83,17 @@ export default {
   },
   beforeMount() {
     console.log(this.pInfo);
-    this.solutionDetail = this.pInfo;
-    this.solutionId = this.pId;
+    if(isEmpty(this.pInfo) && isEmpty(this.solutionDetail)){
+      console.log('无法获取文章数据');
+      this.$router.push('/news');
+    }
+    if(isEmpty(this.solutionDetail)){
+      this.solutionDetail = this.pInfo;
+    }
+    if(isEmpty(this.solutionId)){
+      this.solutionId = this.pId;
+    }
+
     this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
     this.solutionDetail.date_time  = timestampToTime(this.solutionDetail.date_time);
     this.timer = setTimeout(()=>{

+ 20 - 19
server/control/c_base.js

@@ -169,16 +169,6 @@ async function updateCarousel(id,updateItems){
   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];
-}
-
 /**
  * 文件上传
  * @param type
@@ -300,25 +290,36 @@ async function deleteFile(fileId){
 }
 
 
-async function getTypes(){
+async function getBaseData(){
   // 同时获取所有需要获取的基础数据
-  let err,pType,nType;
+  let err,pType,nType,carousel;
   // todo 同时获取所有需要获取的基础数据
-  [err,pType,nType] = await handleAll(
+  [err,pType,nType,carousel] = await handleAll(
     d_product.loadTypes(),
-    d_news.loadTypes()
+    d_news.loadTypes(),
+    d_base.getCarousel({state: dbField.db_base.carouselState.enable}),
   );
   if (err) {
     log.error(`[基础数据] 获取基础数据类型分类失败 ${err.message}`);
     return [{eCode: codeMap.ServerError, eMsg: `获取基础数据失败`}, null];
   }
   // 合并数据
-  let types = {
+  let baseData = {
     pType,
-    nType
+    nType,
+    carousel,
   };
-  log.info(`[基础数据] 类型分类获取成功 程序类型数量:${pType.length} 文章类型数量:${nType.length}`);
-  return [null,types];
+  // 轮播数据转换
+  carousel = carousel.map(item=>{
+    item.filePath = filePathToUrl(item.fileType,item.filePath);
+    return item;
+  });
+  log.info(`[基础数据] 类型分类获取成功
+                程序类型数量:${pType.length}
+                文章类型数量:${nType.length}
+                轮播数据数量:${carousel.length}
+                `);
+  return [null,baseData];
 }
 module.exports = {
   getEnableCarousel,
@@ -329,7 +330,7 @@ module.exports = {
   uploadFile,
   searchFiles,
   deleteFile,
-  getTypes,
+  getBaseData,
 
 }
 

+ 1 - 1
server/control/product.js

@@ -43,7 +43,7 @@ async function getProductInfo(id)
         eMsg:`无法找到对应产品`
       },null]
   }
-  console.log(data);
+  // console.log(data);
   return [null,data];
 }
 

+ 5 - 0
server/database/d_base.js

@@ -48,6 +48,10 @@ function addCarousel(sort,fileId,type,value,valueShowText,updateTime){
                     VALUES (?,?,?,?,?,?)`;
   return mysql.pq(sql,[sort,fileId,type,value,valueShowText,updateTime]);
 }
+function deleteCarousel(id){
+  let sql = `DELETE FROM hfy_carousel WHERE id = ?`;
+  return mysql.pq(sql,[id]);
+}
 
 function updateCarousel(id,updateParam,time){
   let sql = `UPDATE hfy_carousel SET `;
@@ -142,6 +146,7 @@ module.exports = {
   getCarousel,
   getCarouselById,
   addCarousel,
+  deleteCarousel,
   updateCarousel,
   uploadFiles,
   loadFiles,

+ 6 - 3
server/database/d_product.js

@@ -23,11 +23,14 @@ function getProductInfo(id) {
   let sql = ``;
   let values = [];
   sql += `SELECT
-              p.*
+              p.*,
+              p_type.type_key
           FROM
-            hfy_product as p
+            hfy_product as p,
+            hfy_product_type as p_type
           WHERE
-            p.proid = ?`;
+            p.type_id = p_type.type_id
+            and p.proid = ?`;
   values = [id];
   return mysql.pq(sql, values);
 }

+ 6 - 6
server/router/r_base.js

@@ -175,19 +175,19 @@ router.delete('/file/:fileId',checkLogin(progressField.session_hfy),async (req,r
   }
 })
 
-router.get('/types',async (req,res)=>{
+router.get('/base',async (req,res)=>{
   try{
-    log.info(`[类型] 获取基础类型信息`);
+    log.info(`[基础数据获取] 获取基础数据信息,前后端通用数据`);
     // 从数据库中读取数据.
-    let [err, data] = await c.getTypes();
+    let [err, data] = await c.getBaseData();
     if(err){
-      log.warn(`[类型] 获取类型失败 ${err.eMsg||err.message}`);
-      return controlError(res, err,`获取类型失败 ${err.eMsg||err.message}`);
+      log.warn(`[基础数据获取] 获取基础数据 ${err.eMsg||err.message}`);
+      return controlError(res, err,`获取基础数据信息失败 ${err.eMsg||err.message}`);
     }
     return success(res, data);
   }catch (e){
     console.log(e);
-    ServerError(res, e, `获取数据异常 ${e.message}`);
+    ServerError(res, e, `获取基础数据异常 ${e.message}`);
   }
 });
 

+ 9 - 1
store/index.js

@@ -20,6 +20,7 @@ export const indexTypes = {
   mutations: {
     setProductTypes: 'setProductTypes',
     setNewsTypes: 'setNewsTypes',
+    setCarousel: 'setCarousel',
   }
 }
 
@@ -30,6 +31,8 @@ export const modules = {
       pTypes: [],
       // 新闻类别
       nTypes: [],
+      // 轮播数据
+      carousel: [],
     },
     mutations: {
       [indexTypes.mutations.setProductTypes](state, pTypes){
@@ -37,6 +40,9 @@ export const modules = {
       },
       [indexTypes.mutations.setNewsTypes](state, nTypes){
         state.nTypes = nTypes;
+      },
+      [indexTypes.mutations.setCarousel](state, carousel){
+        state.carousel = carousel;
       }
     },
     actions : {
@@ -48,13 +54,14 @@ export const modules = {
           }
           // 获取新闻与产品类别信息
           let err, res;
-          [err, res] = await handle(axios.get(baseUrl + apiMap.baseTypes.path));
+          [err, res] = await handle(axios.get(baseUrl + apiMap.baseDatas.path));
           if(err){return console.log(err);}
           let result = res.data;
           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);
+          commit(indexTypes.mutations.setCarousel, data.carousel);
         }
 
       },
@@ -62,6 +69,7 @@ export const modules = {
     getters: {
       pTypes: state => state.pTypes,
       nTypes: state => state.nTypes,
+      carousel: state => state.carousel,
       productTypes: state => {
         let arr = state.pTypes;
         return _transform(arr);

+ 13 - 1
until/typeTool.js

@@ -51,9 +51,21 @@ function isObject(v){
     return v instanceof Object
 }
 
+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 false;
+  }else{
+    return !v
+  }
+}
 
 module.exports = {
     toNumber,
     toString,
-    toBoolean
+    toBoolean,
+    isEmpty
 }