浏览代码

[banner][增加]:banner图片接口的渲染

tags/2.2.4
meo 6 年前
父节点
当前提交
ec254cda15
共有 10 个文件被更改,包括 245 次插入205 次删除
  1. +53
    -51
      app.js
  2. +26
    -22
      app.json
  3. +4
    -1
      components/banner/index.js
  4. +4
    -4
      components/banner/index.wxml
  5. +4
    -0
      config/config.js
  6. +42
    -12
      pages/index/index.js
  7. +1
    -1
      pages/index/index.wxml
  8. +1
    -1
      pages/index/rushToBuy/index.wxml
  9. +1
    -1
      pages/user/index.wxml
  10. +109
    -112
      utils/HttpBasics.js

+ 53
- 51
app.js 查看文件

@@ -1,26 +1,26 @@
let config = require('./config/config.js')
let config = require("./config/config.js");
const Http = require("./utils/HttpBasics"); const Http = require("./utils/HttpBasics");
App({ App({
data: {}, data: {},
onLaunch: function(options) { onLaunch: function(options) {
var that = this; var that = this;
that.globalData.sceneAddress = options.scene; that.globalData.sceneAddress = options.scene;
that.getLocation()
that.userLogin()
that.getLocation();
that.userLogin();
}, },
/** /**
* 获取地址位置信息 * 获取地址位置信息
*/ */
getLocation: function() { getLocation: function() {
wx.getLocation({ wx.getLocation({
type: 'wgs84',
type: "wgs84",
success: function(res) { success: function(res) {
console.log("getLocation", res); console.log("getLocation", res);
}, },
fail: error => { fail: error => {
console.log(error); console.log(error);
} }
})
});
}, },
/** /**
* 用户登录 * 用户登录
@@ -29,43 +29,44 @@ App({
var that = this; var that = this;
// 登录 // 登录
wx.login({ wx.login({
success: ({
code
}) => {
success: ({ code }) => {
Http.post({ Http.post({
url: config.api.login, url: config.api.login,
data: { data: {
appId: config.weapp.AppId, appId: config.weapp.AppId,
code: code, 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({ wx.getSetting({
success: res => { success: res => {
console.log('getSetting', res)
if (res.authSetting['scope.userInfo']) {
console.log("getSetting", res);
if (res.authSetting["scope.userInfo"]) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({ wx.getUserInfo({
success: res => { success: res => {
// 可以将 res 发送给后台解码出 unionId // 可以将 res 发送给后台解码出 unionId
console.log('getUserInfo', res)
console.log("getUserInfo", res);
} }
})
});
} }
} }
})
});
}, },

/** /**
* 检查用户是否有车 * 检查用户是否有车
*/ */
checkUserCarStatus: function() { checkUserCarStatus: function() {
var that = this
var that = this;
Http.get({ Http.get({
url: config.api.userCarCount, url: config.api.userCarCount,
data: {} data: {}
}).then(res => { }).then(res => {
if (res.data > 0) { 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共同登录 * car共同登录
*/ */
userCarLogin: function() { userCarLogin: function() {
var that = this
var that = this;
if (!that.globalData.carLogin) { if (!that.globalData.carLogin) {
// 共同登录 // 共同登录
Http.post({ Http.post({
@@ -118,13 +120,13 @@ App({
phone: that.globalData.phone phone: that.globalData.phone
} }
}).then(res => { }).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") { 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: { globalData: {
@@ -146,4 +148,4 @@ App({
name: "陕西大悦城" name: "陕西大悦城"
} }
} }
})
});

+ 26
- 22
app.json 查看文件

@@ -1,49 +1,53 @@
{ {
"pages":[
"pages": [
"pages/index/index", "pages/index/index",
"pages/getuserinfo/index", "pages/getuserinfo/index",
"pages/getphoneInfo/index", "pages/getphoneInfo/index",
"pages/market/index",
"pages/user/index",
"pages/market/index",
"pages/user/index",
"pages/coupon/detail/index", "pages/coupon/detail/index",
"pages/shop/detail/index", "pages/shop/detail/index",
"pages/rushToBuy/index", "pages/rushToBuy/index",
"pages/shop/index/index",
"pages/shop/index/index",
"pages/couponorder/index/index", "pages/couponorder/index/index",
"pages/couponorder/detail/index", "pages/couponorder/detail/index",
"pages/order/detail/index", "pages/order/detail/index",
"pages/order/index/index", "pages/order/index/index",
"pages/success/index",
"pages/success/index",
"pages/login/index", "pages/login/index",
"pages/park/park", "pages/park/park",
"pages/passCar/passCar", "pages/passCar/passCar",
"pages/addPark/addPark" "pages/addPark/addPark"
], ],
"tabBar": { "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", "pagePath": "pages/passCar/passCar",
"iconPath": "assets/img/pass1.png", "iconPath": "assets/img/pass1.png",
"selectedIconPath": "assets/img/pass0.png", "selectedIconPath": "assets/img/pass0.png",
"text": "停车" "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", "navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat", "navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
"navigationBarTextStyle": "black"
}, },
"networkTimeout": { "networkTimeout": {
"request": 10000, "request": 10000,


+ 4
- 1
components/banner/index.js 查看文件

@@ -4,7 +4,7 @@ Component({
* 组件的属性列表 * 组件的属性列表
*/ */
properties: { properties: {
imgUrls: {
list: {
value: [], value: [],
type: Array, type: Array,
}, },
@@ -20,6 +20,9 @@ Component({
/** /**
* 组件的方法列表 * 组件的方法列表
*/ */
ready(){
console.log(this.data.list)
},
methods: { methods: {
swiperChange: function (e) { swiperChange: function (e) {
this.setData({ this.setData({


+ 4
- 4
components/banner/index.wxml 查看文件

@@ -1,13 +1,13 @@
<view class="index-slide-view"> <view class="index-slide-view">
<swiper class="index-slide" bindchange="swiperChange" circular="true" autoplay="true" interval="3000" duration="500">
<block wx:for="{{imgUrls}}" wx:key="unique">
<swiper class="index-slide" bindchange="swiperChange" circular="true" autoplay="true" interval="3000" duration="500">
<block wx:for="{{list}}" wx:key="unique">
<swiper-item> <swiper-item>
<image src="{{item}}" class="index-slide-image" />
<image data-id="{{item.id}}" src="{{item.coverImg}}" class="index-slide-image" />
</swiper-item> </swiper-item>
</block> </block>
</swiper> </swiper>
<view class="dots"> <view class="dots">
<block wx:for="{{imgUrls}}" wx:key="unique">
<block wx:for="{{list}}" wx:key="unique">
<view class="dot{{index == swiperCurrent ? ' active' : ''}}"></view> <view class="dot{{index == swiperCurrent ? ' active' : ''}}"></view>
</block> </block>
</view> </view>

+ 4
- 0
config/config.js 查看文件

@@ -107,6 +107,10 @@ var config = {
* 优免券领取 * 优免券领取
*/ */
getCoupon: '/car/getCoupon', getCoupon: '/car/getCoupon',
/**
* banner
*/
bannerlist:'/wxCampaign/list'
}, },


weapp: { weapp: {


+ 42
- 12
pages/index/index.js 查看文件

@@ -1,14 +1,10 @@
const Http = require("../../utils/HttpBasics"); const Http = require("../../utils/HttpBasics");
//获取应用实例
const app = getApp();
const config = require("../../config/config");
let app = getApp();
Page({ Page({
data: { data: {
market: app.globalData.market, 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, swiperCurrent: 0,
scrollTop: 0 scrollTop: 0
}, },
@@ -20,22 +16,56 @@ Page({
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function() {},
onShow: function(options) {
console.log("0000");
console.log(app.globalData.token);
},
onLoad: function(options) { onLoad: function(options) {
var that = this; var that = this;
var scene = decodeURIComponent(options.scene);
if (app.globalData.token && app.globalData.token != null) { if (app.globalData.token && app.globalData.token != null) {
console.log("index ++ " + app.globalData.token); console.log("index ++ " + app.globalData.token);
} else { } else {
// 由于是网络请求,可能会在 Page.onLoad 之后才返回 // 由于是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况 // 所以此处加入 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({ wx.showLoading({
title: "加载中" title: "加载中"
}); });
var scene = decodeURIComponent(options.scene);
setTimeout(function() { setTimeout(function() {
wx.hideLoading(); wx.hideLoading();
}, 2200); }, 2200);


+ 1
- 1
pages/index/index.wxml 查看文件

@@ -4,7 +4,7 @@
<text class="iconfont icon-dingweib txt"></text> {{market.name}} <text class="iconfont icon-choose"></text> <text class="iconfont icon-dingweib txt"></text> {{market.name}} <text class="iconfont icon-choose"></text>
</navigator> </navigator>
</view> --> </view> -->
<c-banner imgUrls="{{imgUrls}}" />
<c-banner wx:key="unique" list="{{list}}"/>
<c-rushToBuy /> <c-rushToBuy />
<c-coupons /> <c-coupons />
</view> </view>

+ 1
- 1
pages/index/rushToBuy/index.wxml 查看文件

@@ -8,7 +8,7 @@
<view class="commodity-info-name">{{item.subTitle}}</view> <view class="commodity-info-name">{{item.subTitle}}</view>
<view class="commodity-info-price"> <view class="commodity-info-price">
<text class="commodity-info-price-p">¥{{item.salePriceStr}}</text> <text class="commodity-info-price-p">¥{{item.salePriceStr}}</text>
<text class="commodity-info-price-o">¥{{item.salePriceStr}}</text>
<text class="commodity-info-price-o">¥{{item.priceStr}}</text>
</view> </view>
</view> </view>
</navigator> </navigator>


+ 1
- 1
pages/user/index.wxml 查看文件

@@ -42,7 +42,7 @@
</view> </view>
</view> </view>
</navigator> </navigator>
<navigator url="/pages/market/index">
<navigator url="/pages/passCar/passCar" open-type="switchTab">
<view class="user-btn app-border-bottom"> <view class="user-btn app-border-bottom">
<view>智能停车</view> <view>智能停车</view>
<view> <view>


+ 109
- 112
utils/HttpBasics.js 查看文件

@@ -1,116 +1,113 @@
const config = require('../config/config.js')
const config = require("../config/config.js");
class HttpBasics { 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();
module.exports = new HttpBasics();

正在加载...
取消
保存