zjh 5 år sedan
förälder
incheckning
76e42b822c
9 ändrade filer med 174 tillägg och 21 borttagningar
  1. 62 0
      api/request.js
  2. 8 0
      api/urls.js
  3. 1 0
      components/navBar/navBar.js
  4. 8 1
      pages/index/index.js
  5. 8 0
      pages/me/me.js
  6. 1 1
      pages/me/me.wxml
  7. 83 16
      pages/search/search.js
  8. 1 1
      pages/search/search.wxml
  9. 2 2
      project.config.json

+ 62 - 0
api/request.js

@@ -0,0 +1,62 @@
+import urls from './urls'
+ 
+const service = {
+  get (url,data) {
+    return new Promise((resolve,reject) => {
+      wx.request({
+        method: 'get',
+        url: url,
+        data: data,
+        header: {"content-type": "application/json"},
+        success: (res) =>{
+          // 调用接口成功
+          resolve(res)
+        },
+        fail: (err) => {
+          // 调用接口失败
+          reject(err)
+        }
+      })
+    })
+  },
+  post (url,data) {
+    return new Promise((resolve,reject) => {
+      wx.request({
+        method: 'post',
+        url: url,
+        data: data,
+        header: {"content-type": "application/x-www-form-urlencoded"},
+        success: (res) =>{
+          // 调用接口成功
+          resolve(res)
+        },
+        fail: (err) => {
+          // 调用接口失败
+          reject(err)
+        }
+      })
+    })
+  }
+}
+
+module.exports = {
+  // 获取新闻列表
+  getNewsList: (data) => {
+    return new Promise((resolve,reject)=> {
+      resolve(service.get(urls.newsList,data))
+    })
+  },
+  // 获取新闻详情
+  getCateList: (data) => {
+    return new Promise((resolve,reject)=> {
+      resolve(service.get(urls.cateList,data))
+    })
+  },
+  //搜索
+  getSearch: (data) => {
+    return new Promise((resolve,reject)=> {
+      resolve(service.post(urls.search,data))
+    })
+  },
+
+}

+ 8 - 0
api/urls.js

@@ -0,0 +1,8 @@
+const host = 'http://192.168.1.60:6900';
+
+const urls ={
+    newsList:host + '/news/mainpage',
+    search: host + '/search'
+}
+
+module.exports = urls;

+ 1 - 0
components/navBar/navBar.js

@@ -47,6 +47,7 @@ Component({
         that.setStyle();
     },
     data: {
+        
 
     },
     methods: {

+ 8 - 1
pages/index/index.js

@@ -2,7 +2,8 @@
 //获取应用实例
 import * as echarts from '../../ec-canvas/echarts';
 var imageUtil = require('../../utils/window.js'); 
-var Chart=null;
+const apiServer = require('../../api/request');
+var Chart = null;
 const app = getApp()
 var timeData = [
   '2020/6/1', '2009/6/2', '2009/6/3', '2009/6/4', '2009/6/5', '2009/6/6', '2009/6/7', '2009/6/8', '2009/6/9', '2009/6/10',
@@ -313,6 +314,7 @@ Page({
     // }).exec();
 },
   onLoad: function () {
+    // this.getNewsList();
     let sysinfo = wx.getSystemInfoSync(),
     windowHeight = sysinfo.windowHeight,
     statusHeight = sysinfo.statusBarHeight, 
@@ -421,6 +423,11 @@ Page({
     catchTouchMove:function(res){
       return false
     },
+    getNewsList:function(){
+      apiServer.getNewsList().then((res)=>{
+        console.log(res);
+      })
+    },
   //初始化图表
   init_echarts: function () {
     this.echartsComponnet.init((canvas, width, height) => {

+ 8 - 0
pages/me/me.js

@@ -106,5 +106,13 @@ Page({
     wx.navigateTo({
       url: '../attention/attention',
     })
+  },
+  gotoAbout(){
+    wx.showToast({
+      title: '正在开发中',
+      icon:'loading',
+      duration:500
+    })
   }
+
 })

+ 1 - 1
pages/me/me.wxml

@@ -27,7 +27,7 @@
       </view> 
   </view>
   <view class="mineButton">
-      <view class="mine">
+      <view class="mine" bindtap="gotoAbout">
         <text class="mineText">关于我们</text>
         <text class="mineRight">></text>
         </view>

+ 83 - 16
pages/search/search.js

@@ -1,4 +1,5 @@
 // pages/search/search.js
+const apiServer = require('../../api/request');
 Page({
 
   /**
@@ -8,20 +9,20 @@ Page({
     list: [],
     inputValue: null,
     resultList:[
-      {
-        title:'AppL',
-        subtitle:"APPL INC",
-        Increase:"1.22",
-        digital:"33",
-        data:[52,56,355,444]
-      },
-      {
-        title:'AppL',
-        subtitle:"APPL INC",
-        Increase:"1.22",
-        digital:"33",
-        data:[52,56,355,44554]
-      },
+      // {
+      //   title:'AppL',
+      //   subtitle:"APPL INC",
+      //   Increase:"1.22",
+      //   digital:"33",
+      //   data:[52,56,355,444]
+      // },
+      // {
+      //   title:'AppL',
+      //   subtitle:"APPL INC",
+      //   Increase:"1.22",
+      //   digital:"33",
+      //   data:[52,56,355,44554]
+      // },
     ]
   },
 
@@ -29,13 +30,78 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    this.get
+    var _this = this;
+    wx.getStorage({
+      key: 'historySearch',
+      success(res) {
+        _this.setData({
+          list: res.data
+        })
+      }
+    })
   },
   blur: function (e) {
     this.setData({
       inputValue: e.detail.value
     })
-    // this.search();
+    this.search();
+  },
+  search:function(){
+    let data ={
+      search:this.data.inputValue
+    };
+    apiServer.getSearch(data).then((res) =>{
+      if(res.statusCode == 200){
+        console.log(res.data);
+      }else{
+        wx.showToast({
+          title: '搜索失败',
+          icon: 'none'
+        })
+      }
+      
+    }) 
+  },
+  save: function () {
+    var list = this.data.list;
+    if (list.indexOf(this.data.inputValue) == -1 & this.data.inputValue != '') {
+      list.push(this.data.inputValue);
+    }
+    this.setData({
+      list: list
+    })
+    wx.setStorage({
+      key: 'historySearch',
+      data: list
+    })   
+  },
+  searchName: function (e) {
+    this.setData({
+      inputValue: e.currentTarget.dataset.value
+    })
+    this.search();
+  },
+  remove: function () {
+    var _this = this;
+    wx.showModal({
+      title: '提示',
+      content: '确认清空所有记录?',
+      success(res) {
+        if (res.confirm) {
+          wx.removeStorage({
+            key: 'historySearch',
+            success() {
+              _this.setData({
+                list: []
+              })
+            }
+          })
+        } else if (res.cancel) {
+          console.log('用户点击取消')
+        }
+      }
+    })
   },
   clean:function(){
     var _this=this
@@ -46,6 +112,7 @@ Page({
    },100)
  },
  detail:function(e){
+  this.save();
   wx.navigateTo({
     url: '../item/item'
   });

+ 1 - 1
pages/search/search.wxml

@@ -16,7 +16,7 @@
 
   <view class='list'>
      <view class="key" wx:if="{{list.length==0}}">暂无搜索记录</view>
-     <!-- <view class="key" wx:for="{{list}}" wx:key="" bindtap='searchName' data-value='{{item}}'>{{item}}</view> -->
+     <view class="key" wx:for="{{list}}" wx:key="key" bindtap='searchName' data-value='{{item}}'>{{item}}</view>
   </view>
   <view style="clear:both"></view>
    <!-- <view  class='search_result' wx:if="{{inputValue}}"> -->

+ 2 - 2
project.config.json

@@ -4,7 +4,7 @@
 		"ignore": []
 	},
 	"setting": {
-		"urlCheck": true,
+		"urlCheck": false,
 		"es6": true,
 		"enhance": false,
 		"postcss": true,
@@ -25,7 +25,7 @@
 			"disablePlugins": [],
 			"outputPath": ""
 		},
-		"useCompilerModule": false,
+		"useCompilerModule": true,
 		"userConfirmedUseCompilerModuleSwitch": false,
 		"compileHotReLoad": false,
 		"useIsolateContext": true