| @@ -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: "陕西大悦城" | |||
| } | |||
| } | |||
| }) | |||
| }); | |||
| @@ -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, | |||
| @@ -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({ | |||
| @@ -1,13 +1,13 @@ | |||
| <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> | |||
| <image src="{{item}}" class="index-slide-image" /> | |||
| <image data-id="{{item.id}}" src="{{item.coverImg}}" class="index-slide-image" /> | |||
| </swiper-item> | |||
| </block> | |||
| </swiper> | |||
| <view class="dots"> | |||
| <block wx:for="{{imgUrls}}" wx:key="unique"> | |||
| <block wx:for="{{list}}" wx:key="unique"> | |||
| <view class="dot{{index == swiperCurrent ? ' active' : ''}}"></view> | |||
| </block> | |||
| </view> | |||
| @@ -107,6 +107,10 @@ var config = { | |||
| * 优免券领取 | |||
| */ | |||
| getCoupon: '/car/getCoupon', | |||
| /** | |||
| * banner | |||
| */ | |||
| bannerlist:'/wxCampaign/list' | |||
| }, | |||
| weapp: { | |||
| @@ -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); | |||
| @@ -4,7 +4,7 @@ | |||
| <text class="iconfont icon-dingweib txt"></text> {{market.name}} <text class="iconfont icon-choose"></text> | |||
| </navigator> | |||
| </view> --> | |||
| <c-banner imgUrls="{{imgUrls}}" /> | |||
| <c-banner wx:key="unique" list="{{list}}"/> | |||
| <c-rushToBuy /> | |||
| <c-coupons /> | |||
| </view> | |||
| @@ -8,7 +8,7 @@ | |||
| <view class="commodity-info-name">{{item.subTitle}}</view> | |||
| <view class="commodity-info-price"> | |||
| <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> | |||
| </navigator> | |||
| @@ -42,7 +42,7 @@ | |||
| </view> | |||
| </view> | |||
| </navigator> | |||
| <navigator url="/pages/market/index"> | |||
| <navigator url="/pages/passCar/passCar" open-type="switchTab"> | |||
| <view class="user-btn app-border-bottom"> | |||
| <view>智能停车</view> | |||
| <view> | |||
| @@ -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(); | |||
| module.exports = new HttpBasics(); | |||