Explorar el Código

fix:
1. 新接口制作对接

kindring hace 2 años
padre
commit
0d1b70f2e0

+ 2 - 0
components/productTypes.vue

@@ -20,9 +20,11 @@
 <script>
 import langMap from "@/map/langMap";
 import {pTypes} from "~/map/productMap";
+import BigTitle from "~/components/public/bigTitle.vue";
 
 export default {
   name: "productTypes",
+  components: {BigTitle},
   props: {
     lang:{
       default: langMap.lang.cn

+ 2 - 0
components/solutionTypes.vue

@@ -20,9 +20,11 @@
 <script>
 import langMap from "@/map/langMap";
 import {sTypes} from "~/map/solutionMap";
+import BigTitle from "~/components/public/bigTitle.vue";
 
 export default {
   name: "solutionTypes",
+  components: {BigTitle},
   props: {
     lang:{
       default: langMap.lang.cn

+ 26 - 0
map/apiMap.js

@@ -0,0 +1,26 @@
+export const baseUrl = 'http://127.0.0.1:3000';
+export const apiMap = {
+  searchProduct: {
+    path: `/api/product/search`,
+  },
+  productInfo: {
+    path: `/api/product`
+  },
+  searchSolution: {
+    path: `/api/solution/search`,
+  },
+  solutionInfo: {
+    path: `/api/solution`
+  },
+  addPageRead: {
+    path: `/api/news/read`
+  },
+  searchNews: {
+    path: `/api/news/search`,
+  },
+  newsInfo: {
+    // 新闻与解决方案都是文章,不多做接口
+    path: `/api/solution`
+  },
+}
+

+ 13 - 21
nuxt.config.js

@@ -1,5 +1,16 @@
 import * as path from "path";
-
+const devPort = 3000;
+const serverPort = 3000;
+const env = {
+    dev: {
+      MODE: 'development',
+      ENV_API: `http://127.0.0.1:${devPort}`   //测试服务器地址
+    },
+    pro: {
+      MODE: 'production',
+      ENV_API: `http://127.0.0.1:${serverPort}`  // 正式服务器地址
+    }
+}
 function loadSvgConfig(config, ctx) {
   // 排除 nuxt 原配置的影响,Nuxt 默认有vue-loader,会处理svg,img等
   // 找到匹配.svg的规则,然后将存放svg文件的目录排除
@@ -64,25 +75,6 @@ export default {
       proxy: true
     },
     proxy: {
-      '/api': {
-        target: 'http://szhfy.com.cn/', // 目标接口域名
-        pathRewrite: {
-          '^/api': '/api', // 把 /api 替换成 /
-          changeOrigin: true // 表示是否跨域
-        }
-      },
-      '/public': {
-        target: 'http://szhfy.com.cn/', // 目标接口域名
-        pathRewrite: {
-          changeOrigin: true // 表示是否跨域
-        }
-      },
-      '/Public': {
-        target: 'http://szhfy.com.cn/', // 目标接口域名
-        pathRewrite: {
-          changeOrigin: true // 表示是否跨域
-        }
-      }
     },
 
     // Build Configuration (https://go.nuxtjs.dev/config-build)
@@ -111,7 +103,7 @@ export default {
       },
     },
     server: {
-      port: 3000, // default: 3000
+      port: devPort, // default: 3000
       host: '0.0.0.0', // default: localhost
     },
     generate: {

+ 5 - 1
pages/about/index.vue

@@ -97,7 +97,7 @@
             <div class="address-item-content">
               <div class="address-item-content-item">
                 <span>地址:</span>
-                <span>深圳市龙岗区园山街道荷坳社区长金路26号鸿祥发创意园厂房B栋407-408室。</span>
+                <span>深圳市龙岗区园山街道荷坳社区龙岗大道8288号,大运软件小镇8栋301</span>
               </div>
               <div class="address-item-content-item">
                 <span>电话:</span>
@@ -130,8 +130,12 @@
 import langMap from "@/map/langMap";
 import defaultFooter from "~/components/footer/defaultFooter";
 import {isMediaView} from "@/until/mediaView";
+import LucencyHeader from "~/components/header/lucencyHeader.vue";
+import ItemBanner from "~/components/banner/itemBanner.vue";
+import DefaultFooter from "~/components/footer/defaultFooter.vue";
 export default {
   name: "aboutIndex",
+  components: {DefaultFooter, ItemBanner, LucencyHeader},
   props:['uLang'],
   data(){
     return {

+ 20 - 24
pages/news/_type.vue

@@ -1,57 +1,53 @@
 <template>
 <!--  <product-index :p-type="type" :p-product="products"/>-->
 <!--  <solution-index :p-type="type" :p-solution="solutions"></solution-index>-->
-  <news-index :p-type="type" :p-news="solutions"></news-index>
+  <news-index :p-type="type" :p-news="solutions" :p-page-data="basePageData"></news-index>
 </template>
 
 <script>
 import productIndex from '@/pages/product/index.vue'
 import handle from "~/until/handle";
 import axios from "axios";
-import qs from "qs";
 import SolutionIndex from "@/pages/solution/index";
-const pageLimit = 5;
+import {apiMap, baseUrl} from "~/map/apiMap";
 export default {
   name: "typeNewsPage",
   props:[],
   async asyncData(ctx){
-    // ctx.searchProduct();
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=ctx.key;
-
-    queryData['type']=ctx.params.type?ctx.params.type:'all';
-    queryData['page']=1;
-    queryData['limit']=pageLimit;
     // 获取数据
-    let url = 'http://szhfy.com.cn/api/searchNews.php';
-    let [err,res] = await handle(axios.post(
-      url,
-      qs.stringify(queryData)
-    ));
+    let url = baseUrl + apiMap.searchNews.path;
+    let type = ctx.params.type?ctx.params.type:'all';
+    url += `?type=${type}&p=1`
+    let [err,res] = await handle(axios.get( url));
     if(err){
       console.log(err);
       return {};
     }
     let result = res.data;
-    if(result.rcode === 1){
-      return {solutions:result.data}
+    if(result.code === 1){
+      let pageData = {
+        limit: result.limit,
+        page: result.page,
+        total: result.total,
+        count: result.count,
+      }
+      return {
+        news: result.data,
+        basePageData: pageData,
+      }
     }else{
-      console.error(result.msg);
-      console.log(result);
-      return {solutions:[]}
+      return {products:[]}
     }
   },
   data(){
     return {
       type:  'all',
-      solutions: []
+      basePageData: {},
+      news: []
     }
   },
   beforeMount() {
-    // console.log('动态页面执行');
     this.type = this.$route.params.type?this.$route.params.type:'all';
-    // console.log(this.type);
   },
   components:{
     SolutionIndex,

+ 58 - 79
pages/news/index.vue

@@ -19,32 +19,36 @@ import qs from "qs";
 import langMap from "@/map/langMap";
 import handle from "@/until/handle";
 import {isMediaView} from "@/until/mediaView";
+import LucencyHeader from "~/components/header/lucencyHeader.vue";
+import ItemBanner from "~/components/banner/itemBanner.vue";
+import DefaultFooter from "~/components/footer/defaultFooter.vue";
+import {apiMap, baseUrl} from "~/map/apiMap";
 
 const pageLimit = 5;
 export default {
   name: "newIndex",
-  props:['uLang','pType','pKey','pNews'],
+  components: {DefaultFooter, ItemBanner, LucencyHeader},
+  props:['uLang','pType','pKey','pNews','pPageData'],
   async asyncData(ctx){
-    // ctx.searchProduct();
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=ctx.key;
-    queryData['type']=ctx.type;
-    queryData['page']=1;
-    queryData['limit']=pageLimit;
-    // 获取数据
-    let url = 'http://szhfy.com.cn/api/searchNews.php';
-    let [err,res] = await handle(axios.post(
-      url,
-      qs.stringify(queryData)
-    ));
+    let url = baseUrl + apiMap.searchNews.path;
+    url += `?type=all&p=1`
+    let [err,res] = await handle(axios.get( url));
     if(err){
       console.log(err);
       return {};
     }
     let result = res.data;
-    if(result.rcode === 1){
-      return {news:result.data}
+    if(result.code === 1){
+      let pageData = {
+        limit: result.limit,
+        page: result.page,
+        total: result.total,
+        count: result.count,
+      }
+      return {
+        news: result.data,
+        basePageData: pageData,
+      }
     }else{
       console.error(result.msg);
       console.log(result);
@@ -61,26 +65,27 @@ export default {
       nowTotal: 2,
       limit:pageLimit,
       news: this.pNews?this.pNews:[],
+      basePageData: {},
       pageSave: {
 
       },
       isPhone: false
     }
   },
+  beforeMount() {
+    let pageData;
+    if (this.pPageData){
+      this.basePageData = this.pPageData
+    }
+    pageData = this.basePageData;
+    this.updatePageData(pageData);
+  },
   mounted() {
     this.isPhone = isMediaView(0,1024);
     this.$root.$on('changeLang',this.switchLang);
     this.$root.$on('changeNewsType',this.selectType);
     this.$root.$on('changePage',this.changePageHandle);
     // this.$root.$on('changeProductType',this.selectType);
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=this.key;
-    queryData['type']=this.type;
-    queryData['page']=this.page;
-    queryData['limit']=this.limit;
-    let data = qs.stringify(queryData);
-    this.loadPageData(data);
   },
   methods: {
     switchLang(nextLang) {
@@ -105,70 +110,44 @@ export default {
       this.searchNews();
     },
     async searchNews(){
-      const queryData = {};
-      // console.log(ctx)
-      queryData['key']=this.key;
-      queryData['type']=this.type;
-      queryData['page']=this.page;
-      queryData['limit']=this.limit;
       // 获取数据
-      let url = '/api/searchNews.php';
-      let data = qs.stringify(queryData);
-      let [err,res] = await handle(this.$axios.post(
-        url,
-        data
-      ));
-      if(err){
-        console.log(err);
-        return null;
-      }
+      let url = apiMap.searchProduct.path;
+      url += `?key=${this.key}&type=${this.type}&p=${this.page}`
+      let [err,res] = await handle(axios.get(url));
+      if(err){ console.log(err); return null; }
+
       let result = res.data;
-      console.log(result)
-      if(result.rcode === 1){
-        this.news = result.data?result.data:[];
-        await this.loadPageData(data);
+      if(result.code === 1){
+        this.news = result.data;
+        let pageData;
+        if(result.total){
+          // 更新页面信息
+          pageData = {
+            limit: result.limit,
+            page: result.page,
+            total: result.total,
+            count: result.count,
+          }
+        }else if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
+          pageData = this.pageSave[this.type][this.key]
+        }
+        this.updatePageData(pageData);
       }else{
         console.error(result.msg);
         console.log(result);
       }
     },
-    async loadPageData(queryData){
-      let url = '/api/getNewsPage.php';
-      // let
-      let err,res;
-      let pageData = null;
-      if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
-        pageData = this.pageSave[this.type][this.key]
-      }else{
-        [err,res] = await handle(this.$axios.post(
-          url,
-          queryData
-        ));
-        if(err){
-          console.error(err);
-        }else{
-          let result = res.data;
-          if(result.rcode === 1){
-            pageData = result.data?result.data:{};
-          }else{
-            console.error(result.msg);
-            console.log(result);
-          }
-        }
+    updatePageData(pageData){
+      if(!this.pageSave[this.type]){
+        this.pageSave[this.type] = {}
       }
-      if (pageData){
-        this.nowTotal = Math.ceil(pageData.count / pageData.limit);
-        this.nowCount = pageData.count;
-        if(!this.pageSave[this.type]){
-          this.pageSave[this.type] = {}
-        }
-        if(!this.pageSave[this.type][this.key]){
-          this.pageSave[this.type][this.key] = pageData;
-        }
-      }else{
-        this.nowTotal = 1;
-        this.nowCount = 1;
+      if(!this.pageSave[this.type][this.key]){
+        this.pageSave[this.type][this.key] = pageData;
       }
+      let nowTotal = Math.ceil(pageData.total / pageData.limit);
+      let nowCount = pageData.total;
+      this.nowTotal = nowTotal;
+      this.nowCount = nowCount;
     }
   }
 }

+ 32 - 2
pages/news/item/_type.vue

@@ -1,17 +1,23 @@
 <template>
 <!--  <item-index :p-type="type" />-->
-  <item-index :p-type="type"></item-index>
+  <item-index :p-type="type" :p-info="solutionInfo" :p-id="pId"></item-index>
 </template>
 
 <script>
 import ItemIndex from "~/pages/news/item/index";
+import {apiMap, baseUrl} from "~/map/apiMap";
+import {toNumber} from "~/server/tools/typeTool";
+import handle from "~/until/handle";
+import axios from "axios";
+
 export default {
   name: "newsItemType",
   components: {ItemIndex},
   data(){
     return {
       type:  '',
-      products: []
+      pId: 0,
+      solutionInfo: []
     }
   },
   beforeMount() {
@@ -22,6 +28,30 @@ export default {
     }
     // console.log(this.type);
   },
+  async asyncData(ctx){
+    let err,res;
+    let id = ctx.query.id;
+    // id转数字
+    let url = baseUrl + apiMap.newsInfo.path ;
+    if(!toNumber(id)){ctx.redirect(`/news`);}
+    url += `/${id}`;
+    [err,res] = await handle(axios.get(url));
+    if(err){
+      // 加载失败,返回至产品页面
+      console.log(`查询数据失败`);
+      ctx.redirect(`/news`);
+      return {pId:id}
+    }
+    let result = res.data;
+    if(result.code === 1){
+      console.log(result.data);
+      return {pId:id, solutionInfo:result.data}
+    }else{
+      console.log(`查询数据失败,服务器异常`);
+      ctx.redirect(`/news`);
+    }
+    return {pId:id}
+  },
 }
 </script>
 

+ 10 - 31
pages/news/item/index.vue

@@ -25,6 +25,7 @@
 </template>
 
 <script>
+import axios from "axios";
 import langMap from "~/map/langMap";
 import defaultFooter from "~/components/footer/defaultFooter";
 import {getTypeSubText, getTypeText} from "~/map/newMap";
@@ -33,11 +34,14 @@ import {timestampToTime} from "~/until/time";
 import {unescapeHtml} from "~/until/unescapeHtml";
 import {isMediaView} from "@/until/mediaView";
 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";
 
 export default {
   name: "newsItemIndex",
-  props:['uLang','pType'],
-  components:{BigTitle, defaultFooter},
+  props:['uLang','pType', 'pInfo', "pId"],
+  components:{ItemBanner, LucencyHeader, BigTitle, defaultFooter},
   data(){
     return {
       langType: langMap.lang,
@@ -51,14 +55,10 @@ export default {
     }
   },
   beforeMount() {
-    const queryString = window.location.search;
-    const params = new URLSearchParams(queryString);
-    if(params&&params.get('id')){
-      this.solutionId = params.get('id');
-    }else{
-      window.location.href = '/news'
-    }
-    this.loadSolutionDetail();
+    console.log(this.pInfo);
+    this.solutionDetail = this.pInfo;
+    this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
+    this.solutionDetail.date_time  = timestampToTime(this.solutionDetail.date_time);
     this.timer = setTimeout(()=>{
       this.addRead();
     },1000*10)
@@ -81,27 +81,6 @@ export default {
     getAbbrText(str) {
       return langMap.getAbbrText(this.lang, str);
     },
-    async loadSolutionDetail(){
-      let err,res;
-      let url = `/api/getSolution.php?id=${this.solutionId}`;
-      [err,res] = await handle(this.$axios.$get(url));
-      if(err) {
-        console.log(err);
-        return alert(err.message);
-      }
-      console.log(typeof res.code)
-      if(res.code === 1){
-        this.solutionDetail = res.data;
-        // console.log(this.solutionDetail.detail)
-        this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
-        // console.log(this.solutionDetail.detail)
-        this.solutionDetail.date_time  = timestampToTime(this.solutionDetail.date_time);
-      }else{
-        console.log('not match result');
-        console.log(res);
-        return alert('加载解决方案失败!!!');
-      }
-    },
     async addRead(){
       let err,res;
       let url = `/api/addNewsRead.php?id=${this.solutionId}`;

+ 18 - 20
pages/product/_type.vue

@@ -1,52 +1,50 @@
 <template>
-  <product-index :p-type="type" :p-product="products"/>
+  <product-index :p-type="type" :p-product="products" :p-page-data="basePageData"/>
 </template>
 
 <script>
 import productIndex from '@/pages/product/index.vue'
 import handle from "~/until/handle";
 import axios from "axios";
-import qs from "qs";
+import {apiMap, baseUrl} from "~/map/apiMap";
 export default {
   name: "typeProductPage",
   props:[],
   async asyncData(ctx){
-    // ctx.searchProduct();
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=ctx.key;
-
-    queryData['type']=ctx.params.type?ctx.params.type:'all';
-    queryData['page']=1;
     // 获取数据
-    let url = 'http://szhfy.com.cn/api/searchProduct.php';
-    let [err,res] = await handle(axios.post(
-      url,
-      qs.stringify(queryData)
-    ));
+    let url = baseUrl + apiMap.searchProduct.path;
+    let type = ctx.params.type?ctx.params.type:'all';
+    url += `?type=${type}&p=1`
+    let [err,res] = await handle(axios.get( url));
     if(err){
       console.log(err);
       return {};
     }
     let result = res.data;
-    if(result.rcode === 1){
-      return {products:result.data}
+    if(result.code === 1){
+      let pageData = {
+        limit: result.limit,
+        page: result.page,
+        total: result.total,
+        count: result.count,
+      }
+      return {
+        products: result.data,
+        basePageData: pageData,
+      }
     }else{
-      console.error(result.msg);
-      console.log(result);
       return {products:[]}
     }
   },
   data(){
     return {
       type:  'all',
+      basePageData: {},
       products: []
     }
   },
   beforeMount() {
-    // console.log('动态页面执行');
     this.type = this.$route.params.type?this.$route.params.type:'all';
-    // console.log(this.type);
   },
   components:{
     productIndex

+ 61 - 76
pages/product/index.vue

@@ -21,32 +21,38 @@ import qs from "qs"
 import axios from "axios"
 import handle from "~/until/handle";
 import {isMediaView} from "@/until/mediaView";
+import LucencyHeader from "~/components/header/lucencyHeader.vue";
+import DefaultFooter from "~/components/footer/defaultFooter.vue";
+import {apiMap, baseUrl} from "~/map/apiMap";
 export default {
   name: "index",
-  props:['uLang','pType','pKey','pProduct'],
+  props:['uLang','pType','pKey','pProduct','pPageData'],
   components:{
+    DefaultFooter,
+    LucencyHeader,
     productBanner
   },
   async asyncData(ctx){
-    // ctx.searchProduct();
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=ctx.key;
-    queryData['type']=ctx.type;
-    queryData['page']=1;
     // 获取数据
-    let url = '/api/product/search';
-    let [err,res] = await handle(axios.post(
-      url,
-      qs.stringify(queryData)
-    ));
+    let url = baseUrl + apiMap.searchProduct.path;
+    url += `?type=all&p=1`
+    let [err,res] = await handle(axios.get( url));
     if(err){
       console.log(err);
       return {};
     }
     let result = res.data;
     if(result.code === 1){
-      return {products:result.data}
+      let pageData = {
+        limit: result.limit,
+        page: result.page,
+        total: result.total,
+        count: result.count,
+      }
+      return {
+        products: result.data,
+        basePageData: pageData,
+      }
     }else{
       console.error(result.msg);
       console.log(result);
@@ -62,18 +68,27 @@ export default {
       nowCount: 199,
       nowTotal: 2,
       products: this.pProduct?this.pProduct:[],
-      pageSave: {
-
-      },
+      basePageData: {},
+      pageSave: {},
       isPhone: false
     }
   },
+  beforeMount() {
+    let pageData;
+    if (this.pPageData){
+      this.basePageData = this.pPageData
+    }
+    pageData = this.basePageData;
+    this.updatePageData(pageData);
+  },
   mounted() {
     this.isPhone = isMediaView(0,1024);
     this.$root.$on('changeLang',this.switchLang);
     this.$root.$on('searchProductKey',this.changeProductKeyHandle);
     this.$root.$on('changeProductType',this.selectType);
     this.$root.$on('changePage',this.changePageHandle);
+
+
     // this.loadData();
   },
   methods:{
@@ -107,75 +122,45 @@ export default {
       this.searchProduct();
     },
     async searchProduct(){
-      // const formData = new FormData();
-      // formData.append('key',this.key);
-      // formData.append('type',this.type);
-      // formData.append('page',this.page);
-      const queryData = {};
-      // console.log(ctx)
-      queryData['key']=this.key;
-      queryData['type']=this.type;
-      queryData['page']=this.page;
       // 获取数据
-      let url = '/api/product/search';
-      let data = qs.stringify(queryData);
-      let [err,res] = await handle(this.$axios.post(
-        url,
-        data
-      ));
-      if(err){
-        console.log(err);
-        return null;
-      }
+      let url = apiMap.searchProduct.path;
+      url += `?key=${this.key}&type=${this.type}&p=${this.page}`
+      let [err,res] = await handle(axios.get(url));
+      if(err){ console.log(err); return null; }
+
       let result = res.data;
       if(result.code === 1){
         this.products = result.data;
-        // this.loadPageData(data);
+        let pageData;
+        if(result.total){
+          // 更新页面信息
+          pageData = {
+            limit: result.limit,
+            page: result.page,
+            total: result.total,
+            count: result.count,
+          }
+        }else if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
+          pageData = this.pageSave[this.type][this.key]
+        }
+        this.updatePageData(pageData);
       }else{
         console.error(result.msg);
         console.log(result);
       }
     },
-    // async loadPageData(queryData){
-    //   let url = '/api/getProductPage.php';
-    //   // let
-    //   let err,res;
-    //   let pageData = null;
-    //   if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
-    //     pageData = this.pageSave[this.type][this.key]
-    //   }else{
-    //     [err,res] = await handle(this.$axios.post(
-    //       url,
-    //       queryData
-    //     ));
-    //     if(err){
-    //       console.error(err);
-    //     }else{
-    //       let result = res.data;
-    //       if(result.rcode === 1){
-    //         pageData = result.data;
-    //       }else{
-    //         console.error(result.msg);
-    //         console.log(result);
-    //       }
-    //     }
-    //   }
-    //   if (pageData){
-    //     this.nowTotal = Math.ceil(pageData.count / pageData.limit);
-    //     this.nowCount = pageData.count;
-    //     if(!this.pageSave[this.type]){
-    //       this.pageSave[this.type] = {}
-    //     }
-    //     if(!this.pageSave[this.type][this.key]){
-    //       this.pageSave[this.type][this.key] = pageData;
-    //     }
-    //   }else{
-    //     this.nowTotal = 1;
-    //     this.nowCount = 1;
-    //   }
-    //
-    //
-    // }
+    updatePageData(pageData){
+      if(!this.pageSave[this.type]){
+        this.pageSave[this.type] = {}
+      }
+      if(!this.pageSave[this.type][this.key]){
+        this.pageSave[this.type][this.key] = pageData;
+      }
+      let nowTotal = Math.ceil(pageData.total / pageData.limit);
+      let nowCount = pageData.total;
+      this.nowTotal = nowTotal;
+      this.nowCount = nowCount;
+    }
   }
 }
 </script>

+ 31 - 3
pages/product/item/_type.vue

@@ -1,25 +1,53 @@
 <template>
-  <item-index :p-type="type" />
+  <item-index :p-type="type" :p-info="productionInfo" />
 </template>
 
 <script>
 import ItemIndex from "~/pages/product/item/index";
+import {apiMap, baseUrl} from "~/map/apiMap";
+import handle from "~/until/handle";
+import axios from "axios";
+import {toNumber} from "~/server/tools/typeTool";
 export default {
   name: "itemType",
   components: {ItemIndex},
   data(){
     return {
       type:  '',
-      products: []
+      productionInfo: {},
+      loadErr: false,
     }
   },
+  async asyncData(ctx){
+    let err,res;
+    let id = ctx.query.id;
+    // id转数字
+    let url = baseUrl + apiMap.productInfo.path ;
+    if(!toNumber(id)){ctx.redirect(`/product`);}
+    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 {productionInfo:result.data}
+    }else{
+      console.log(`查询数据失败,服务器异常`);
+      ctx.redirect(`/product`);
+    }
+    return {}
+  },
   beforeMount() {
     // console.log('动态页面执行');
     this.type = this.$route.params.type;
     if(!this.type){
       return window.location.href = '/product'
     }
-    // console.log(this.type);
   },
 }
 </script>

+ 13 - 13
pages/product/item/index.vue

@@ -37,6 +37,7 @@
 </template>
 
 <script>
+import axios from "axios";
 import langMap from "~/map/langMap";
 import { getTypeText,getTypeSubText, pTypes} from "~/map/productMap";
 import handle from "~/until/handle";
@@ -46,11 +47,14 @@ import DefaultFooter from "../../../components/footer/defaultFooter";
 import LucencyHeader from "../../../components/header/lucencyHeader";
 import ItemBanner from "../../../components/banner/itemBanner";
 import {isMediaView} from "@/until/mediaView";
+import {apiMap, baseUrl} from "~/map/apiMap";
+import BigTitle from "~/components/public/bigTitle.vue";
 
 export default {
   name: "itemIndex",
-  components: {ItemBanner, LucencyHeader, DefaultFooter, qTab},
-  props:['uLang','pType'],
+  components: {BigTitle, ItemBanner, LucencyHeader, DefaultFooter, qTab},
+  props:['uLang','pType', 'pInfo'],
+
   data(){
     return {
       langType: langMap.lang,
@@ -65,14 +69,10 @@ export default {
     }
   },
   beforeMount() {
-    const queryString = window.location.search;
-    const params = new URLSearchParams(queryString);
-    if(params&&params.get('id')){
-      this.productId = params.get('id');
-    }else{
-      window.location.href = '/product'
-    }
-    this.loadProductDetail();
+    console.log(this.pInfo);
+    this.productDetail = this.pInfo;
+    console.log(this.productDetail.detail)
+    this.productDetail.detail = unescape(this.productDetail.detail);
   },
   mounted() {
     console.log(this.pType);
@@ -89,19 +89,19 @@ export default {
     },
     async loadProductDetail(){
       let err,res;
-      let url = `/api/getProduct.php?id=${this.productId}`;
+      let url = apiMap.productInfo.path;
+      url += `/${this.productId}`
       [err,res] = await handle(this.$axios.get(url));
       if(err){
         console.error(err);
         return alert(err.message);
       }
       let result = res.data;
-      if(result.rcode === 1){
+      if(result.code === 1){
         this.productDetail = result.data;
         console.log(this.productDetail.detail)
         this.productDetail.detail = unescape(this.productDetail.detail);
         console.log(this.productDetail.detail)
-
       }else{
         console.log('not match result');
         console.log(result);

+ 18 - 20
pages/solution/_type.vue

@@ -1,6 +1,6 @@
 <template>
 <!--  <product-index :p-type="type" :p-product="products"/>-->
-  <solution-index :p-type="type" :p-solution="solutions"></solution-index>
+  <solution-index :p-type="type" :p-solution="solutions" :p-page-data="basePageData"></solution-index>
 </template>
 
 <script>
@@ -9,48 +9,46 @@ import handle from "~/until/handle";
 import axios from "axios";
 import qs from "qs";
 import SolutionIndex from "@/pages/solution/index";
+import {apiMap, baseUrl} from "~/map/apiMap";
 const pageLimit = 5;
 export default {
   name: "typeSolutionPage",
   props:[],
   async asyncData(ctx){
-    // ctx.searchProduct();
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=ctx.key;
-
-    queryData['type']=ctx.params.type?ctx.params.type:'all';
-    queryData['page']=1;
-    queryData['limit']=pageLimit;
     // 获取数据
-    let url = 'http://szhfy.com.cn/api/searchSolution.php';
-    let [err,res] = await handle(axios.post(
-      url,
-      qs.stringify(queryData)
-    ));
+    let url = baseUrl + apiMap.searchSolution.path;
+    let type = ctx.params.type?ctx.params.type:'all';
+    url += `?type=${type}&p=1&l=5`
+    let [err,res] = await handle(axios.get( url));
     if(err){
       console.log(err);
       return {};
     }
     let result = res.data;
-    if(result.rcode === 1){
-      return {solutions:result.data}
+    if(result.code === 1){
+      let pageData = {
+        limit: result.limit,
+        page: result.page,
+        total: result.total,
+        count: result.count,
+      }
+      return {
+        solutions: result.data,
+        basePageData: pageData,
+      }
     }else{
-      console.error(result.msg);
-      console.log(result);
       return {solutions:[]}
     }
   },
   data(){
     return {
       type:  'all',
+      basePageData: {},
       solutions: []
     }
   },
   beforeMount() {
-    // console.log('动态页面执行');
     this.type = this.$route.params.type?this.$route.params.type:'all';
-    // console.log(this.type);
   },
   components:{
     SolutionIndex,

+ 59 - 85
pages/solution/index.vue

@@ -24,38 +24,43 @@ import langMap from "~/map/langMap";
 import handle from "~/until/handle";
 import axios from "axios";
 import {isMediaView} from "@/until/mediaView";
+import LucencyHeader from "~/components/header/lucencyHeader.vue";
+import DefaultFooter from "~/components/footer/defaultFooter.vue";
+import {apiMap, baseUrl} from "~/map/apiMap";
 
 const pageLimit = 5;
 export default {
   name: "solutionIndex",
-  props:['uLang','pType','pKey','pSolution'],
+  props:['uLang','pType','pKey','pSolution','pPageData'],
   components:{
+    DefaultFooter,
+    LucencyHeader,
     productBanner,
     itemBanner,
     solutionTypes,
     solutionList
   },
   async asyncData(ctx){
-    // ctx.searchProduct();
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=ctx.key;
-    queryData['type']=ctx.type;
-    queryData['page']=1;
-    queryData['limit']=pageLimit;
     // 获取数据
-    let url = 'http://szhfy.com.cn/api/searchSolution.php';
-    let [err,res] = await handle(axios.post(
-      url,
-      qs.stringify(queryData)
-    ));
+    let url = baseUrl + apiMap.searchSolution.path;
+    url += `?type=all&p=1&l=5`
+    let [err,res] = await handle(axios.get( url));
     if(err){
       console.log(err);
       return {};
     }
     let result = res.data;
-    if(result.rcode === 1){
-      return {solutions:result.data}
+    if(result.code === 1){
+      let pageData = {
+        limit: result.limit,
+        page: result.page,
+        total: result.total,
+        count: result.count,
+      }
+      return {
+        solutions: result.data,
+        basePageData: pageData,
+      }
     }else{
       console.error(result.msg);
       console.log(result);
@@ -72,26 +77,25 @@ export default {
       nowTotal: 2,
       limit:pageLimit,
       solutions:this.pSolution?this.pSolution:[],
-      pageSave: {
-
-      },
+      basePageData: {},
+      pageSave: {},
       isPhone: false
     }
   },
+  beforeMount() {
+    let pageData;
+    if (this.pPageData){
+      this.basePageData = this.pPageData
+    }
+    pageData = this.basePageData;
+    this.updatePageData(pageData);
+  },
   mounted() {
     this.isPhone = isMediaView(0,1024);
     this.$root.$on('changeLang',this.switchLang);
     this.$root.$on('changeSolutionType',this.selectType);
     this.$root.$on('changePage',this.changePageHandle);
     // this.$root.$on('changeProductType',this.selectType);
-    const queryData = {};
-    // console.log(ctx)
-    queryData['key']=this.key;
-    queryData['type']=this.type;
-    queryData['page']=this.page;
-    queryData['limit']=this.limit;
-    let data = qs.stringify(queryData);
-    this.loadPageData(data);
   },
   methods:{
     switchLang(nextLang){
@@ -116,74 +120,44 @@ export default {
       this.searchSolution();
     },
     async searchSolution(){
-      // const formData = new FormData();
-      // formData.append('key',this.key);
-      // formData.append('type',this.type);
-      // formData.append('page',this.page);
-      const queryData = {};
-      // console.log(ctx)
-      queryData['key']=this.key;
-      queryData['type']=this.type;
-      queryData['page']=this.page;
-      queryData['limit']=this.limit;
       // 获取数据
-      let url = '/api/searchSolution.php';
-      let data = qs.stringify(queryData);
-      let [err,res] = await handle(this.$axios.post(
-        url,
-        data
-      ));
-      if(err){
-        console.log(err);
-        return null;
-      }
+      let url = apiMap.searchSolution.path;
+      url += `?key=${this.key}&type=${this.type}&p=${this.page}&l=5`
+      let [err,res] = await handle(axios.get(url));
+      if(err){ console.log(err); return null; }
+
       let result = res.data;
-      console.log(result)
-      if(result.rcode === 1){
-        this.solutions = result.data?result.data:[];
-        this.loadPageData(data);
+      if(result.code === 1){
+        this.solutions = result.data;
+        let pageData;
+        if(result.total){
+          // 更新页面信息
+          pageData = {
+            limit: result.limit,
+            page: result.page,
+            total: result.total,
+            count: result.count,
+          }
+        }else if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
+          pageData = this.pageSave[this.type][this.key]
+        }
+        this.updatePageData(pageData);
       }else{
         console.error(result.msg);
         console.log(result);
       }
     },
-    async loadPageData(queryData){
-      let url = '/api/getSolutionPage.php';
-      // let
-      let err,res;
-      let pageData = null;
-      if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
-        pageData = this.pageSave[this.type][this.key]
-      }else{
-        [err,res] = await handle(this.$axios.post(
-          url,
-          queryData
-        ));
-        if(err){
-          console.error(err);
-        }else{
-          let result = res.data;
-          if(result.rcode === 1){
-            pageData = result.data?result.data:{};
-          }else{
-            console.error(result.msg);
-            console.log(result);
-          }
-        }
+    updatePageData(pageData){
+      if(!this.pageSave[this.type]){
+        this.pageSave[this.type] = {}
       }
-      if (pageData){
-        this.nowTotal = Math.ceil(pageData.count / pageData.limit);
-        this.nowCount = pageData.count;
-        if(!this.pageSave[this.type]){
-          this.pageSave[this.type] = {}
-        }
-        if(!this.pageSave[this.type][this.key]){
-          this.pageSave[this.type][this.key] = pageData;
-        }
-      }else{
-        this.nowTotal = 1;
-        this.nowCount = 1;
+      if(!this.pageSave[this.type][this.key]){
+        this.pageSave[this.type][this.key] = pageData;
       }
+      let nowTotal = Math.ceil(pageData.total / pageData.limit);
+      let nowCount = pageData.total;
+      this.nowTotal = nowTotal;
+      this.nowCount = nowCount;
     }
   }
 }

+ 31 - 2
pages/solution/item/_type.vue

@@ -1,16 +1,21 @@
 <template>
-  <item-index :p-type="type" />
+  <item-index :p-type="type" :p-info="solutionInfo" :p-id="pId"/>
 </template>
 
 <script>
 import ItemIndex from "~/pages/solution/item/index";
+import {apiMap, baseUrl} from "~/map/apiMap";
+import {toNumber} from "~/server/tools/typeTool";
+import handle from "~/until/handle";
+import axios from "axios";
 export default {
   name: "solutionItemType",
   components: {ItemIndex},
   data(){
     return {
       type:  '',
-      products: []
+      pId: 0,
+      solutionInfo: {}
     }
   },
   beforeMount() {
@@ -21,6 +26,30 @@ export default {
     }
     // console.log(this.type);
   },
+  async asyncData(ctx){
+    let err,res;
+    let id = ctx.query.id;
+    // id转数字
+    let url = baseUrl + apiMap.solutionInfo.path ;
+    if(!toNumber(id)){ctx.redirect(`/solution`);}
+    url += `/${id}`;
+    [err,res] = await handle(axios.get(url));
+    if(err){
+      // 加载失败,返回至产品页面
+      console.log(`查询数据失败`);
+      ctx.redirect(`/solution`);
+      return {pId:id}
+    }
+    let result = res.data;
+    if(result.code === 1){
+      console.log(result.data);
+      return {pId:id, solutionInfo:result.data}
+    }else{
+      console.log(`查询数据失败,服务器异常`);
+      ctx.redirect(`/solution`);
+    }
+    return {pId:id}
+  },
 }
 </script>
 

+ 15 - 14
pages/solution/item/index.vue

@@ -30,18 +30,22 @@ import defaultFooter from "~/components/footer/defaultFooter";
 import {getTypeSubText, getTypeText} from "~/map/solutionMap";
 import handle from "~/until/handle";
 import {timestampToTime} from "~/until/time";
-import {unescapeHtml} from "~/until/unescapeHtml";
+import {unescape, unescapeHtml} from "~/until/unescapeHtml";
 import {isMediaView} from "@/until/mediaView";
+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";
 
 export default {
   name: "solutionItemIndex",
-  props:['uLang','pType'],
-  components:{defaultFooter},
+  props:['uLang', 'pType', 'pInfo', "pId"],
+  components:{LucencyHeader, ItemBanner, BigTitle, defaultFooter},
   data(){
     return {
       langType: langMap.lang,
       lang: this.uLang?this.uLang:langMap.lang.cn,
-      solutionId: null,
+      solutionId: this.pId,
       solutionDetail: {},
       productTypeText: getTypeText(this.pType),
       productTypeSubText: getTypeSubText(this.pType),
@@ -50,14 +54,10 @@ export default {
     }
   },
   beforeMount() {
-    const queryString = window.location.search;
-    const params = new URLSearchParams(queryString);
-    if(params&&params.get('id')){
-      this.solutionId = params.get('id');
-    }else{
-      window.location.href = '/solution'
-    }
-    this.loadSolutionDetail();
+    console.log(this.pInfo);
+    this.solutionDetail = this.pInfo;
+    this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
+    this.solutionDetail.date_time  = timestampToTime(this.solutionDetail.date_time);
     this.timer = setTimeout(()=>{
       this.addRead();
     },1000*10)
@@ -79,7 +79,7 @@ export default {
     },
     async loadSolutionDetail(){
       let err,res;
-      let url = `/api/getSolution.php?id=${this.solutionId}`;
+      let url = apiMap.solutionInfo.path;
       [err,res] = await handle(this.$axios.$get(url));
       if(err) {
         console.log(err);
@@ -100,7 +100,8 @@ export default {
     },
     async addRead(){
       let err,res;
-      let url = `/api/addNewsRead.php?id=${this.solutionId}`;
+      let url = apiMap.addPageRead;
+      url += `?id=${this.solutionId}`
       [err,res] = await handle(this.$axios.$get(url));
       if(err) {
         console.log(err);

+ 4 - 1
pages/support/index.vue

@@ -26,6 +26,9 @@ import langMap from "@/map/langMap";
 import handle from "@/until/handle";
 import {unescapeHtml} from "@/until/unescapeHtml";
 import {isMediaView} from "@/until/mediaView";
+import ItemBanner from "~/components/banner/itemBanner.vue";
+import Downloads from "~/components/supportCom/downloads.vue";
+import DefaultFooter from "~/components/footer/defaultFooter.vue";
 
 function getFileIcon(fileName){
   // 获取文件后缀
@@ -54,7 +57,7 @@ function getFileIcon(fileName){
 export default {
   name: "index",
   props:['uLang'],
-  components: { lucencyHeader },
+  components: {DefaultFooter, Downloads, ItemBanner, lucencyHeader },
   data(){
     return {
       lang: this.uLang?this.uLang:langMap.lang.cn,

+ 15 - 0
server/control/c_news.js

@@ -0,0 +1,15 @@
+const {searchHandle} = require('../tools/searchSql');
+const {handle} = require('../tools/handle');
+const codeMap = require("../map/rcodeMap");
+const log = require("../logger").logger("c_solution","info");
+
+const d_news = require("../database/d_news");
+const d_solution = require("~/server/database/d_solution");
+
+async function addReadNum(newId){
+
+}
+
+module.exports = {
+  addReadNum
+}

+ 72 - 1
server/control/c_solution.js

@@ -1,6 +1,7 @@
 const {searchHandle} = require('../tools/searchSql');
 const {handle} = require('../tools/handle');
 const d_solution = require("../database/d_solution");
+const codeMap = require("../map/rcodeMap");
 const log = require("../logger").logger("c_solution","info")
 
 /**
@@ -21,7 +22,77 @@ async function loadSolution(key,p,l){
   return [null,res];
 }
 
+async function getSolutionInfo(id)
+{
+  let [err,res] = await handle(d_solution.getSolutionInfo(id));
+  if(err){
+    return [err,null];
+  }
+
+  let data = {};
+  if(res.length){
+    data = res[0];
+  }else{
+    return [
+      {
+        eCode:codeMap.NotFound,
+        eMsg:`无法找到对应产品`
+      },null]
+  }
+
+  return [null,data];
+}
+
+async function searchSolution(type, key, p, l)
+{
+  p = p || 1;
+  l = l || 10;
+  let _params = {
+    parentType: 1,
+  }
+  if(type !== 'all'){
+    _params.type = type;
+  }
+  if(key){
+    _params.key = key
+  }
+
+
+  return await searchHandle(
+    '搜索产品失败',
+    d_solution.searchSolution,
+    _params,
+    p,
+    l);
+}
+
+async function searchNews(type, key, p, l)
+{
+  p = p || 1;
+  l = l || 10;
+  let _params = {
+    parentType: 2,
+  }
+  if(type !== 'all'){
+    _params.type = type;
+  }
+  if(key){
+    _params.key = key
+  }
+
+
+  return await searchHandle(
+    '搜索新闻失败',
+    d_solution.searchSolution,
+    _params,
+    p,
+    l);
+}
+
 module.exports = {
-  loadSolution
+  loadSolution,
+  searchSolution,
+  searchNews,
+  getSolutionInfo
 }
 

+ 22 - 3
server/control/product.js

@@ -1,6 +1,7 @@
 const d_product = require('../database/d_product');
 const {searchHandle} = require('../tools/searchSql');
 const {handle} = require('../tools/handle');
+const codeMap = require("../map/rcodeMap");
 const log = require("../logger").logger("c_product","info")
 /**
  * 加载产品
@@ -31,7 +32,19 @@ async function getProductInfo(id)
   if(err){
     return [err,null];
   }
-  return [null,res];
+
+  let data = {};
+  if(res.length){
+    data = res[0];
+  }else{
+    return [
+      {
+        eCode:codeMap.NotFound,
+        eMsg:`无法找到对应产品`
+      },null]
+  }
+
+  return [null,data];
 }
 
 async function searchProduct(type, key, p, l)
@@ -39,10 +52,16 @@ async function searchProduct(type, key, p, l)
   p = p || 1;
   l = l || 10;
   let _params = {
-    key: key,
   }
+  if(type !== 'all'){
+    _params.type = type;
+  }
+  if(key){
+    _params.key = key
+  }
+
  return await searchHandle(
-    '搜索角色失败',
+    '搜索产品失败',
    d_product.searchProducts,
     _params,
     p,

+ 19 - 7
server/database/d_product.js

@@ -16,10 +16,6 @@ function loadProducts(key, page, limit) {
   let _limitSql = limitSql(limit,page);
   sql += _limitSql.sql;
   values.push(..._limitSql.values);
-  console.log(sql);
-  console.log(values);
-  log.info("test");
-  log.info(sql);
   return mysql.pq(sql, values);
 }
 
@@ -40,12 +36,28 @@ function searchProducts(type='array',searchParam,page,limit){
   let sql = ``;
   let values = [];
   if(type === 'count'){
-    sql = `select count(*) as total from hfy_product where 1=1`;
+    sql = `select count(*) as total `;
   }else{
-    sql = `select * from hfy_product where 1=1`;
+    sql = `select
+    p.proid as id,
+    p.remark,p.name,
+    p.image,p.source,
+    p.sourceType,
+    p_type.type_key
+    `;
   }
+  sql += `
+   from
+   hfy_product as p,
+   hfy_product_type as p_type
+  `
+  sql += `where p.type_id = p_type.type_id`
   if(searchParam.key){
-    sql += ` and name like '%${searchParam.key}%'`
+    sql += ` and p.name like '%${searchParam.key}%'`
+  }
+  if(searchParam.type){
+    sql += ` and p_type.type_key = ?`
+    values.push(searchParam.type)
   }
   return searchSql(mysql.pq,type,sql,values,limit,page);
 }

+ 50 - 5
server/database/d_solution.js

@@ -23,14 +23,59 @@ function loadSolution(key, page, limit) {
   let _limitSql = limitSql(limit,page);
   sql += _limitSql.sql;
   values.push(..._limitSql.values);
-  log.info(sql);
-
-  console.log(sql)
-  console.log(values)
+  // log.info(sql);
   return mysql.pq(sql, values);
 }
 
+function searchSolution(type='array',searchParam,page,limit){
+  let sql;
+  let values = [];
+  if(type === 'count'){
+    sql = `select count(*) as total `;
+  }else{
+    sql = `select
+    news.id,
+    news.remark,
+    news.title as name,
+    news.image,
+    news.source,
+    news.sourceType,
+    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`
+  sql += ` and n_type.parent_type = ${searchParam.parentType}`
+  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 getSolutionInfo(id) {
+  let sql = ``;
+  let values = [];
+  sql += `SELECT
+            news.*
+          FROM
+            hfy_news as news
+          WHERE
+            news.id = ?`;
+  values = [id];
+  return mysql.pq(sql, values);
+}
 
 module.exports = {
-  loadSolution
+  loadSolution,
+  searchSolution,
+  getSolutionInfo
+
 }

+ 1 - 1
server/logger.js

@@ -52,7 +52,7 @@ log4js.configure({
         // 设置默认的 categories
         // default: { appenders: ['cheese', 'console'], level: 'info' },
         default: {
-            appenders: [ 'cheese' ], level: 'info'
+            appenders: [ 'cheese','console' ], level: 'info'
         },
     },
 })

+ 2 - 0
server/router/index.js

@@ -2,6 +2,7 @@
 const router = require('express').Router();
 const r_product = require('./r_product');
 const r_solution = require("./r_solution");
+const r_news = require('./r_news')
 router.get('/', (req, res) => {
     res.json({
         code: 200,
@@ -11,5 +12,6 @@ router.get('/', (req, res) => {
 
 router.use('/product',r_product);
 router.use('/solution',r_solution);
+router.use('/news',r_news);
 
 module.exports =  router ;

+ 50 - 0
server/router/r_news.js

@@ -0,0 +1,50 @@
+const router = require('express').Router();
+const {paramFail, ServerError, success, controlError, searchSuccess} = require("../tools/result");
+const c_solution = require("../control/c_solution");
+const typeTool = require("../tools/typeTool");
+const c = require("~/server/control/c_solution");
+const log = require("../logger").logger("r_news","info");
+
+router.get(
+  '/search',
+  async (req, res) => {
+    try{
+      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_solution.searchNews(type, key, p, l);
+      if(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;
+    let {id} = req.query;
+    id = typeTool.toNumber(id);
+    if(!id){
+      paramFail(res, "id is required");
+      return;
+    }
+    [err, result] = await c.addReadNum(id);
+    if(err){ return controlError(res, err, null);}
+    success(res, result);
+  }catch (e) {
+    ServerError(res, null, e.message);
+  }
+})
+
+module.exports = router;

+ 11 - 4
server/router/r_product.js

@@ -2,7 +2,7 @@ const router = require('express').Router();
 const {paramFail, ServerError, success, controlError, searchSuccess} = require("../tools/result");
 const c = require('../control/product');
 const log = require("../logger").logger("r_product","info")
-
+const typeTool = require('../tools/typeTool');
 
 /**
  * 加载产品列表,根据类型
@@ -19,8 +19,8 @@ router.get('/load',
         paramFail(res, "key is required");
         return;
       }
-      console.log(key);
-      log.info(key);
+      // console.log(key);
+      // log.info(key);
       [err, result] = await c.loadProduct(key, p, l);
       if(err){ return controlError(res, err, null);}
       success(res, result);
@@ -36,8 +36,13 @@ router.get(
         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.searchProduct(type, key, p, l);
-        if(err){ return controlError(res, err, null);}
+        if(err){
+          return controlError(res, err, null);}
+        log.info(`result len=${result.arr.length}`)
         searchSuccess(res,
           result.arr,
           result.total,
@@ -62,6 +67,8 @@ router.get('/:id', async (req, res) => {
       paramFail(res, "id is required");
       return;
     }
+    id = typeTool.toNumber(id);
+    log.info(`product info ${id}`);
     [err, result] = await c.getProductInfo(id);
     if(err){ return controlError(res, err, null);}
     success(res, result);

+ 45 - 2
server/router/r_solution.js

@@ -1,7 +1,9 @@
 const router = require('express').Router();
 const {paramFail, ServerError, success, controlError, searchSuccess} = require("../tools/result");
 const c = require("../control/c_solution");
-const log = require("../logger").logger("r_product","info");
+const typeTool = require("../tools/typeTool");
+const log = require("../logger").logger("r_solution","info");
+
 
 /**
  * 加载解决方案
@@ -18,7 +20,6 @@ router.get('/load',
         paramFail(res, "key is required");
         return;
       }
-      console.log(key);
       log.info(key);
       [err, result] = await c.loadSolution(key, p, l);
       if(err){ return controlError(res, err, null);}
@@ -28,5 +29,47 @@ router.get('/load',
     }
 });
 
+router.get(
+  '/search',
+  async (req, res) => {
+    try{
+      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.searchSolution(type, key, p, l);
+      if(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('/:id', async (req, res) => {
+  try{
+    let err, result;
+    let {id} = req.params;
+    id = typeTool.toNumber(id);
+    if(!id){
+      paramFail(res, "id is required");
+      return;
+    }
+    log.info(`get solution info ${id}`);
+    [err, result] = await c.getSolutionInfo(id);
+    if(err){ return controlError(res, err, null);}
+    success(res, result);
+  }catch (e) {
+    ServerError(res, null, e.message);
+  }
+});
 
 module.exports = router;

+ 1 - 1
server/tools/result.js

@@ -7,7 +7,7 @@ function success(res,data) {
   })
 }
 
-function searchSuccess(res, data, total, key, page, limit) {
+function searchSuccess(res, data, total, page, limit) {
   res.json({
     code: rCode.OK,
     data: data,

+ 2 - 0
server/tools/searchSql.js

@@ -36,6 +36,8 @@ async function searchHandle(errorText,dbFn,_params,page,limit){
         [err,response] = await handle(Promise.all([arrPromise]))
     }
     if(err){
+
+        console.log(err);
         return [
           {eCode:codeMap.ServerError,eMsg:`${errorText}`},
           null

+ 5 - 1
server/tools/typeTool.js

@@ -16,7 +16,11 @@ function toNumber(v){
             v = toBoolean(v)
         }
     }
-    return Number(v)
+    if(!v){
+      return 0;
+    }
+    let r = Number(v);
+    return isNaN(r)?0:r;
 }
 
 // 考虑字段类型