From ec254cda15eedb3486384d5d4a26cfd56745ef73 Mon Sep 17 00:00:00 2001
From: meo <958484406@qq.com>
Date: Sat, 25 Aug 2018 22:38:34 +0800
Subject: [PATCH] =?UTF-8?q?[banner][=E5=A2=9E=E5=8A=A0]:banner=E5=9B=BE?=
=?UTF-8?q?=E7=89=87=E6=8E=A5=E5=8F=A3=E7=9A=84=E6=B8=B2=E6=9F=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.js | 104 ++++++++-------
app.json | 48 ++++---
components/banner/index.js | 5 +-
components/banner/index.wxml | 8 +-
config/config.js | 4 +
pages/index/index.js | 54 ++++++--
pages/index/index.wxml | 2 +-
pages/index/rushToBuy/index.wxml | 2 +-
pages/user/index.wxml | 2 +-
utils/HttpBasics.js | 221 +++++++++++++++----------------
10 files changed, 245 insertions(+), 205 deletions(-)
diff --git a/app.js b/app.js
index 648f4d5..876a807 100644
--- a/app.js
+++ b/app.js
@@ -1,26 +1,26 @@
-let config = require('./config/config.js')
+let config = require("./config/config.js");
const Http = require("./utils/HttpBasics");
App({
data: {},
onLaunch: function(options) {
var that = this;
that.globalData.sceneAddress = options.scene;
- that.getLocation()
- that.userLogin()
+ that.getLocation();
+ that.userLogin();
},
/**
* 获取地址位置信息
*/
getLocation: function() {
wx.getLocation({
- type: 'wgs84',
+ type: "wgs84",
success: function(res) {
console.log("getLocation", res);
},
fail: error => {
console.log(error);
}
- })
+ });
},
/**
* 用户登录
@@ -29,43 +29,44 @@ App({
var that = this;
// 登录
wx.login({
- success: ({
- code
- }) => {
+ success: ({ code }) => {
Http.post({
url: config.api.login,
data: {
appId: config.weapp.AppId,
code: code,
- sceneAddress: that.globalData.sceneAddress,
- }
- }).then(res => {
- console.log("req", res);
- that.globalData.token = res.data.token;
- Http.setToken(res.data.token)
- that.checkUserCarStatus()
- that.getUserInfo()
- if (that.couponChannelListCallback) {
- that.couponChannelListCallback(that.globalData.token);
- }
- if (that.couponListCallback) {
- that.couponListCallback(that.globalData.token);
- }
- return Http.post({
- url: config.api.checkUserStatus,
- data: {}
- })
- }).then(res => {}).catch(err => {
- console.log(err)
- if (err.code == 11004) {
- // 用户昵称未授权
- wx.redirectTo({
- url: '../getuserinfo/index',
- })
+ sceneAddress: that.globalData.sceneAddress
}
})
+ .then(res => {
+ console.log("req", res);
+ that.globalData.token = res.data.token;
+ Http.setToken(res.data.token);
+ that.checkUserCarStatus();
+ that.getUserInfo();
+ if (that.couponChannelListCallback) {
+ that.couponChannelListCallback(that.globalData.token);
+ }
+ if (that.couponListCallback) {
+ that.couponListCallback(that.globalData.token);
+ }
+ return Http.post({
+ url: config.api.checkUserStatus,
+ data: {}
+ });
+ })
+ .then(res => {})
+ .catch(err => {
+ console.log(err);
+ if (err.code == 11004) {
+ // 用户昵称未授权
+ wx.redirectTo({
+ url: "../getuserinfo/index"
+ });
+ }
+ });
}
- })
+ });
},
/**
* 获取用户信息
@@ -74,42 +75,43 @@ App({
// 获取用户信息
wx.getSetting({
success: res => {
- console.log('getSetting', res)
- if (res.authSetting['scope.userInfo']) {
+ console.log("getSetting", res);
+ if (res.authSetting["scope.userInfo"]) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
- console.log('getUserInfo', res)
+ console.log("getUserInfo", res);
}
- })
+ });
}
}
- })
+ });
},
+
/**
* 检查用户是否有车
*/
checkUserCarStatus: function() {
- var that = this
+ var that = this;
Http.get({
url: config.api.userCarCount,
data: {}
}).then(res => {
if (res.data > 0) {
// 用户名下有车
- that.globalData.phone = res.data.phone
- that.globalData.supportCar = true
+ that.globalData.phone = res.data.phone;
+ that.globalData.supportCar = true;
// 共同登录
- that.userCarLogin()
+ that.userCarLogin();
}
- })
+ });
},
/**
* car共同登录
*/
userCarLogin: function() {
- var that = this
+ var that = this;
if (!that.globalData.carLogin) {
// 共同登录
Http.post({
@@ -118,13 +120,13 @@ App({
phone: that.globalData.phone
}
}).then(res => {
- that.globalData.carLogin = true
- that.globalData.parkVendor = res.data.vendor
+ that.globalData.carLogin = true;
+ that.globalData.parkVendor = res.data.vendor;
if (res.data.token != "undefined") {
- that.globalData.etcpToken = res.data.token
- console.log("etcpToken", that.globalData.etcpToken)
+ that.globalData.etcpToken = res.data.token;
+ console.log("etcpToken", that.globalData.etcpToken);
}
- })
+ });
}
},
globalData: {
@@ -146,4 +148,4 @@ App({
name: "陕西大悦城"
}
}
-})
\ No newline at end of file
+});
diff --git a/app.json b/app.json
index 3f32221..c62e9e3 100644
--- a/app.json
+++ b/app.json
@@ -1,49 +1,53 @@
{
- "pages":[
+ "pages": [
"pages/index/index",
"pages/getuserinfo/index",
"pages/getphoneInfo/index",
- "pages/market/index",
- "pages/user/index",
+ "pages/market/index",
+ "pages/user/index",
"pages/coupon/detail/index",
"pages/shop/detail/index",
"pages/rushToBuy/index",
- "pages/shop/index/index",
+ "pages/shop/index/index",
"pages/couponorder/index/index",
"pages/couponorder/detail/index",
"pages/order/detail/index",
"pages/order/index/index",
- "pages/success/index",
+ "pages/success/index",
"pages/login/index",
"pages/park/park",
"pages/passCar/passCar",
"pages/addPark/addPark"
],
"tabBar": {
- "color":"#9F9F9F",
- "selectedColor":"#00C0FF",
- "list": [{
- "pagePath": "pages/index/index",
- "iconPath":"assets/img/home-n.png",
- "selectedIconPath":"assets/img/home-y.png",
- "text": "首页"
- }, {
+ "color": "#9F9F9F",
+ "selectedColor": "#00C0FF",
+ "list": [
+ {
+ "pagePath": "pages/index/index",
+ "iconPath": "assets/img/home-n.png",
+ "selectedIconPath": "assets/img/home-y.png",
+ "text": "首页"
+ },
+ {
"pagePath": "pages/passCar/passCar",
"iconPath": "assets/img/pass1.png",
"selectedIconPath": "assets/img/pass0.png",
"text": "停车"
- }, {
- "pagePath": "pages/user/index",
- "iconPath":"assets/img/user-n.png",
- "selectedIconPath":"assets/img/user-y.png",
- "text": "我的"
- }]
+ },
+ {
+ "pagePath": "pages/user/index",
+ "iconPath": "assets/img/user-n.png",
+ "selectedIconPath": "assets/img/user-y.png",
+ "text": "我的"
+ }
+ ]
},
- "window":{
- "backgroundTextStyle":"light",
+ "window": {
+ "backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
- "navigationBarTextStyle":"black"
+ "navigationBarTextStyle": "black"
},
"networkTimeout": {
"request": 10000,
diff --git a/components/banner/index.js b/components/banner/index.js
index 538647b..0d6e5f2 100644
--- a/components/banner/index.js
+++ b/components/banner/index.js
@@ -4,7 +4,7 @@ Component({
* 组件的属性列表
*/
properties: {
- imgUrls: {
+ list: {
value: [],
type: Array,
},
@@ -20,6 +20,9 @@ Component({
/**
* 组件的方法列表
*/
+ ready(){
+ console.log(this.data.list)
+ },
methods: {
swiperChange: function (e) {
this.setData({
diff --git a/components/banner/index.wxml b/components/banner/index.wxml
index 5c91cb9..bad38af 100644
--- a/components/banner/index.wxml
+++ b/components/banner/index.wxml
@@ -1,13 +1,13 @@
-
-
+
+
-
+
-
+
diff --git a/config/config.js b/config/config.js
index 50fedc1..ffee7c0 100755
--- a/config/config.js
+++ b/config/config.js
@@ -107,6 +107,10 @@ var config = {
* 优免券领取
*/
getCoupon: '/car/getCoupon',
+ /**
+ * banner
+ */
+ bannerlist:'/wxCampaign/list'
},
weapp: {
diff --git a/pages/index/index.js b/pages/index/index.js
index 442196c..4af62a4 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -1,14 +1,10 @@
const Http = require("../../utils/HttpBasics");
-//获取应用实例
-const app = getApp();
+const config = require("../../config/config");
+let app = getApp();
Page({
data: {
market: app.globalData.market,
- imgUrls: [
- "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg",
- "http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg",
- "http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg"
- ],
+ list: [],
swiperCurrent: 0,
scrollTop: 0
},
@@ -20,22 +16,56 @@ Page({
/**
* 生命周期函数--监听页面初次渲染完成
*/
- onReady: function() {},
+ onShow: function(options) {
+ console.log("0000");
+ console.log(app.globalData.token);
+ },
onLoad: function(options) {
var that = this;
+ var scene = decodeURIComponent(options.scene);
if (app.globalData.token && app.globalData.token != null) {
console.log("index ++ " + app.globalData.token);
} else {
// 由于是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
- app.tokenCallback = token => {
- console.log("index + " + token);
- };
+ wx.login({
+ success: ({ code }) => {
+ console.log(code);
+ Http.post({
+ url: config.api.login,
+ data: {
+ appId: config.weapp.AppId,
+ code: code,
+ sceneAddress: app.globalData.sceneAddress
+ }
+ }).then(res => {
+ //banner
+ console.log(res);
+ app.globalData.token = res.data.token;
+ console.log(app.globalData.token)
+ Http.setToken(res.data.token);
+ if (res.code == 200) {
+ Http.get({
+ url: config.api.bannerlist,
+ data: {
+ pageNum: 1,
+ pageSize: 10
+ }
+ }).then(res => {
+ console.log(res);
+ that.setData({
+ list: res.data.list
+ })
+ console.log(res.data.list);
+ });
+ }
+ })
+ }
+ })
}
wx.showLoading({
title: "加载中"
});
- var scene = decodeURIComponent(options.scene);
setTimeout(function() {
wx.hideLoading();
}, 2200);
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index 4580098..b8a7665 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -4,7 +4,7 @@
{{market.name}}
-->
-
+
\ No newline at end of file
diff --git a/pages/index/rushToBuy/index.wxml b/pages/index/rushToBuy/index.wxml
index e193931..691add0 100644
--- a/pages/index/rushToBuy/index.wxml
+++ b/pages/index/rushToBuy/index.wxml
@@ -8,7 +8,7 @@
{{item.subTitle}}
¥{{item.salePriceStr}}
- ¥{{item.salePriceStr}}
+ ¥{{item.priceStr}}
diff --git a/pages/user/index.wxml b/pages/user/index.wxml
index eab45f8..17af6f8 100644
--- a/pages/user/index.wxml
+++ b/pages/user/index.wxml
@@ -42,7 +42,7 @@
-
+
智能停车
diff --git a/utils/HttpBasics.js b/utils/HttpBasics.js
index 3162421..4883ab5 100644
--- a/utils/HttpBasics.js
+++ b/utils/HttpBasics.js
@@ -1,116 +1,113 @@
-const config = require('../config/config.js')
+const config = require("../config/config.js");
class HttpBasics {
- constructor(address) {
- if (address) {
- this.address = address;
- }
+ constructor(address) {
+ if (address) {
+ this.address = address;
}
- /**
- * 配置
- */
- config = config;
- /**
- * 请求路径前缀
- */
- address = config.url
- /**
- * 请求头
- */
- headers = {
- "Content-Type": "application/json;charset=UTF-8",
- "token": ""
- };
- /**
- * 设置token
- * @param {*} token
- */
- setToken(token) {
- this.headers.token = token;
- }
- /**
- * 获取数据
- * @param {url,data,headers} param0
- */
- get({ url, data, headers }) {
- headers = { ...this.headers, ...headers };
- url = `${this.address}${url}`;
- // wx.showLoading({
- // title: 'loading...',
- // })
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- header: headers,
- data: data,
- method: "Get",
- success: (res) => {
- // wx.hideLoading();
- this.responseMap(res, resolve, reject)
- },
- fail: (err) => {
- // wx.hideLoading();
- reject(err)
- },
- complete: (res) => {
- }
- })
- })
- }
- /**
- * 提交数据
- * @param {url,data,headers} param0
- */
- post({ url, data, headers }) {
- headers = { ...this.headers, ...headers };
- url = `${this.address}${url}`;
- // wx.showLoading({
- // title: 'loading...',
- // })
- return new Promise((resolve, reject) => {
- wx.request({
- url: url,
- header: headers,
- data: data,
- method: "POST",
- success: (res) => {
- // wx.hideLoading();
- this.responseMap(res, resolve, reject)
- },
- fail: (err) => {
- // wx.hideLoading();
- reject(err)
- },
- complete: (res) => {
- }
- })
- })
- }
- /**
- * 过滤 请求信息
- * @param {*} res
- * @param {*} resolve
- * @param {*} reject
- */
- responseMap=(res, resolve, reject)=> {
- // 网络状态码200
- if (res.statusCode == 200) {
- // 服务器code 200 成功
- if (res.data.code == 200) {
- resolve(res.data);
- } else {
- wx.hideLoading();
- wx.showToast({
- title: res.data.message
- })
- reject(res.data);
- }
- } else {
- console.error("请求出错:", res);
- reject(res.data);
- }
- }
- /** 日志 */
- log(url, body, headers) {
+ }
+ /**
+ * 配置
+ */
+ config = config;
+ /**
+ * 请求路径前缀
+ */
+ address = config.url;
+ /**
+ * 请求头
+ */
+ headers = {
+ "Content-Type": "application/json;charset=UTF-8",
+ token: ""
+ };
+ /**
+ * 设置token
+ * @param {*} token
+ */
+ setToken(token) {
+ this.headers.token = token;
+ }
+ /**
+ * 获取数据
+ * @param {url,data,headers} param0
+ */
+ get({ url, data, headers }) {
+ headers = { ...this.headers, ...headers };
+ url = `${this.address}${url}`;
+ // wx.showLoading({
+ // title: 'loading...',
+ // })
+ return new Promise((resolve, reject) => {
+ wx.request({
+ url: url,
+ header: headers,
+ data: data,
+ method: "Get",
+ success: res => {
+ // wx.hideLoading();
+ this.responseMap(res, resolve, reject);
+ },
+ fail: err => {
+ // wx.hideLoading();
+ reject(err);
+ },
+ complete: res => {}
+ });
+ });
+ }
+ /**
+ * 提交数据
+ * @param {url,data,headers} param0
+ */
+ post({ url, data, headers }) {
+ headers = { ...this.headers, ...headers };
+ url = `${this.address}${url}`;
+ // wx.showLoading({
+ // title: 'loading...',
+ // })
+ return new Promise((resolve, reject) => {
+ wx.request({
+ url: url,
+ header: headers,
+ data: data,
+ method: "POST",
+ success: res => {
+ // wx.hideLoading();
+ this.responseMap(res, resolve, reject);
+ },
+ fail: err => {
+ // wx.hideLoading();
+ reject(err);
+ },
+ complete: res => {}
+ });
+ });
+ }
+ /**
+ * 过滤 请求信息
+ * @param {*} res
+ * @param {*} resolve
+ * @param {*} reject
+ */
+ responseMap = (res, resolve, reject) => {
+ // 网络状态码200
+ if (res.statusCode == 200) {
+ // 服务器code 200 成功
+ if (res.data.code == 200) {
+ resolve(res.data);
+ } else {
+ wx.hideLoading();
+ wx.showToast({
+ title: res.data.message
+ });
+ reject(res.data);
+ }
+ } else {
+ console.error("请求出错:", res);
+ reject(res.data);
}
+ };
+ /** 日志 */
+ log(url, body, headers) {}
}
-module.exports = new HttpBasics();
\ No newline at end of file
+module.exports = new HttpBasics();