U:wx.getUserProfile接口失效后,新增修改用户头像和昵称的页面。
This commit is contained in:
parent
353cad572e
commit
0716b4471c
95
app.js
95
app.js
@ -1,60 +1,47 @@
|
|||||||
var util = require('utils/util.js');
|
var util = require('utils/util.js');
|
||||||
var api = require('config/api.js');
|
var api = require('config/api.js');
|
||||||
App({
|
App({
|
||||||
data: {
|
data: {
|
||||||
deviceInfo: {}
|
deviceInfo: {}
|
||||||
},
|
},
|
||||||
onLaunch: function() {
|
onLaunch: function () {
|
||||||
this.data.deviceInfo = wx.getSystemInfoSync();
|
this.data.deviceInfo = wx.getSystemInfoSync();
|
||||||
console.log(this.data.deviceInfo);
|
console.log(this.data.deviceInfo);
|
||||||
// 展示本地存储能力
|
// 展示本地存储能力
|
||||||
var logs = wx.getStorageSync('logs') || []
|
var logs = wx.getStorageSync('logs') || []
|
||||||
logs.unshift(Date.now())
|
logs.unshift(Date.now())
|
||||||
wx.setStorageSync('logs', logs)
|
wx.setStorageSync('logs', logs)
|
||||||
// 登录
|
// 登录
|
||||||
wx.login({
|
wx.login({
|
||||||
success: res => {
|
success: (res) => {
|
||||||
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
util.request(api.AuthLoginByWeixin, {
|
||||||
}
|
code: res.code
|
||||||
})
|
}, 'POST').then(function (res) {
|
||||||
// 获取用户信息
|
if (res.errno === 0) {
|
||||||
wx.getSetting({
|
let userInfo = res.data.userInfo;
|
||||||
success: res => {
|
wx.setStorageSync('token', res.data.token);
|
||||||
if (res.authSetting['scope.userInfo']) {
|
wx.setStorageSync('userInfo', userInfo);
|
||||||
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
|
}
|
||||||
wx.getUserInfo({
|
|
||||||
success: res => {
|
|
||||||
// 可以将 res 发送给后台解码出 unionId
|
|
||||||
this.globalData.userInfo = res.userInfo
|
|
||||||
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
||||||
// 所以此处加入 callback 以防止这种情况
|
|
||||||
if (this.userInfoReadyCallback) {
|
|
||||||
this.userInfoReadyCallback(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
let that = this;
|
|
||||||
wx.getSystemInfo({ // 获取页面的有关信息
|
|
||||||
success: function(res) {
|
|
||||||
wx.setStorageSync('systemInfo', res)
|
|
||||||
var ww = res.windowWidth;
|
|
||||||
var hh = res.windowHeight;
|
|
||||||
that.globalData.ww = ww;
|
|
||||||
that.globalData.hh = hh;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
let that = this;
|
||||||
|
wx.getSystemInfo({ // 获取页面的有关信息
|
||||||
|
success: function (res) {
|
||||||
|
wx.setStorageSync('systemInfo', res)
|
||||||
|
var ww = res.windowWidth;
|
||||||
|
var hh = res.windowHeight;
|
||||||
|
that.globalData.ww = ww;
|
||||||
|
that.globalData.hh = hh;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
globalData: {
|
||||||
|
userInfo: {
|
||||||
|
nickname: '点我登录',
|
||||||
|
username: '点击登录',
|
||||||
|
avatar: 'http://lucky-icon.meiweiyuxian.com/hio/default_avatar_big.png'
|
||||||
},
|
},
|
||||||
globalData: {
|
token: '',
|
||||||
userInfo: {
|
}
|
||||||
nickname: '点我登录',
|
|
||||||
username: '点击登录',
|
|
||||||
avatar: 'http://lucky-icon.meiweiyuxian.com/hio/default_avatar_big.png'
|
|
||||||
},
|
|
||||||
token: '',
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
109
config/api.js
109
config/api.js
@ -1,57 +1,60 @@
|
|||||||
// const ApiRootUrl = 'http://localhost:8360/api/';
|
const ApiRoot = 'http://localhost:8361';
|
||||||
// const ApiRootUrl = 'http://192.168.0.108:8360/api/';
|
// const ApiRoot = 'http://192.168.0.113:8361';
|
||||||
const ApiRootUrl = 'https://www.guxiaoling.com:8466/api/';
|
// const ApiRoot = 'https://www.qile.club:8688';
|
||||||
|
const ApiRootUrl = ApiRoot + '/api/'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// 登录
|
ApiRoot: ApiRoot,
|
||||||
AuthLoginByWeixin: ApiRootUrl + 'auth/loginByWeixin', //微信登录
|
// 登录
|
||||||
// 首页
|
AuthLoginByWeixin: ApiRootUrl + 'auth/loginByWeixin', //微信登录
|
||||||
IndexUrl: ApiRootUrl + 'index/appInfo', //首页数据接口
|
// 首页
|
||||||
// 分类
|
IndexUrl: ApiRootUrl + 'index/appInfo', //首页数据接口
|
||||||
CatalogList: ApiRootUrl + 'catalog/index', //分类目录全部分类数据接口
|
// 分类
|
||||||
CatalogCurrent: ApiRootUrl + 'catalog/current', //分类目录当前分类数据接口
|
CatalogList: ApiRootUrl + 'catalog/index', //分类目录全部分类数据接口
|
||||||
GetCurrentList: ApiRootUrl + 'catalog/currentlist',
|
CatalogCurrent: ApiRootUrl + 'catalog/current', //分类目录当前分类数据接口
|
||||||
// 购物车
|
GetCurrentList: ApiRootUrl + 'catalog/currentlist',
|
||||||
CartAdd: ApiRootUrl + 'cart/add', // 添加商品到购物车
|
// 购物车
|
||||||
CartList: ApiRootUrl + 'cart/index', //获取购物车的数据
|
CartAdd: ApiRootUrl + 'cart/add', // 添加商品到购物车
|
||||||
CartUpdate: ApiRootUrl + 'cart/update', // 更新购物车的商品
|
CartList: ApiRootUrl + 'cart/index', //获取购物车的数据
|
||||||
CartDelete: ApiRootUrl + 'cart/delete', // 删除购物车的商品
|
CartUpdate: ApiRootUrl + 'cart/update', // 更新购物车的商品
|
||||||
CartChecked: ApiRootUrl + 'cart/checked', // 选择或取消选择商品
|
CartDelete: ApiRootUrl + 'cart/delete', // 删除购物车的商品
|
||||||
CartGoodsCount: ApiRootUrl + 'cart/goodsCount', // 获取购物车商品件数
|
CartChecked: ApiRootUrl + 'cart/checked', // 选择或取消选择商品
|
||||||
CartCheckout: ApiRootUrl + 'cart/checkout', // 下单前信息确认
|
CartGoodsCount: ApiRootUrl + 'cart/goodsCount', // 获取购物车商品件数
|
||||||
// 商品
|
CartCheckout: ApiRootUrl + 'cart/checkout', // 下单前信息确认
|
||||||
GoodsCount: ApiRootUrl + 'goods/count', //统计商品总数
|
// 商品
|
||||||
GoodsDetail: ApiRootUrl + 'goods/detail', //获得商品的详情
|
GoodsCount: ApiRootUrl + 'goods/count', //统计商品总数
|
||||||
GoodsList: ApiRootUrl + 'goods/list', //获得商品列表
|
GoodsDetail: ApiRootUrl + 'goods/detail', //获得商品的详情
|
||||||
GoodsShare: ApiRootUrl + 'goods/goodsShare', //获得商品的详情
|
GoodsList: ApiRootUrl + 'goods/list', //获得商品列表
|
||||||
SaveUserId: ApiRootUrl + 'goods/saveUserId',
|
GoodsShare: ApiRootUrl + 'goods/goodsShare', //获得商品的详情
|
||||||
// 收货地址
|
SaveUserId: ApiRootUrl + 'goods/saveUserId',
|
||||||
AddressDetail: ApiRootUrl + 'address/addressDetail', //收货地址详情
|
// 收货地址
|
||||||
DeleteAddress: ApiRootUrl + 'address/deleteAddress', //保存收货地址
|
AddressDetail: ApiRootUrl + 'address/addressDetail', //收货地址详情
|
||||||
SaveAddress: ApiRootUrl + 'address/saveAddress', //保存收货地址
|
DeleteAddress: ApiRootUrl + 'address/deleteAddress', //保存收货地址
|
||||||
GetAddresses: ApiRootUrl + 'address/getAddresses',
|
SaveAddress: ApiRootUrl + 'address/saveAddress', //保存收货地址
|
||||||
RegionList: ApiRootUrl + 'region/list', //获取区域列表
|
GetAddresses: ApiRootUrl + 'address/getAddresses',
|
||||||
PayPrepayId: ApiRootUrl + 'pay/preWeixinPay', //获取微信统一下单prepay_id
|
RegionList: ApiRootUrl + 'region/list', //获取区域列表
|
||||||
OrderSubmit: ApiRootUrl + 'order/submit', // 提交订单
|
PayPrepayId: ApiRootUrl + 'pay/preWeixinPay', //获取微信统一下单prepay_id
|
||||||
OrderList: ApiRootUrl + 'order/list', //订单列表
|
OrderSubmit: ApiRootUrl + 'order/submit', // 提交订单
|
||||||
OrderDetail: ApiRootUrl + 'order/detail', //订单详情
|
OrderList: ApiRootUrl + 'order/list', //订单列表
|
||||||
OrderDelete: ApiRootUrl + 'order/delete', //订单删除
|
OrderDetail: ApiRootUrl + 'order/detail', //订单详情
|
||||||
OrderCancel: ApiRootUrl + 'order/cancel', //取消订单
|
OrderDelete: ApiRootUrl + 'order/delete', //订单删除
|
||||||
OrderConfirm: ApiRootUrl + 'order/confirm', //物流详情
|
OrderCancel: ApiRootUrl + 'order/cancel', //取消订单
|
||||||
OrderCount: ApiRootUrl + 'order/count', // 获取订单数
|
OrderConfirm: ApiRootUrl + 'order/confirm', //物流详情
|
||||||
OrderCountInfo: ApiRootUrl + 'order/orderCount', // 我的页面获取订单数状态
|
OrderCount: ApiRootUrl + 'order/count', // 获取订单数
|
||||||
OrderExpressInfo: ApiRootUrl + 'order/express', //物流信息
|
OrderCountInfo: ApiRootUrl + 'order/orderCount', // 我的页面获取订单数状态
|
||||||
OrderGoods: ApiRootUrl + 'order/orderGoods', // 获取checkout页面的商品列表
|
OrderExpressInfo: ApiRootUrl + 'order/express', //物流信息
|
||||||
// 足迹
|
OrderGoods: ApiRootUrl + 'order/orderGoods', // 获取checkout页面的商品列表
|
||||||
FootprintList: ApiRootUrl + 'footprint/list', //足迹列表
|
// 足迹
|
||||||
FootprintDelete: ApiRootUrl + 'footprint/delete', //删除足迹
|
FootprintList: ApiRootUrl + 'footprint/list', //足迹列表
|
||||||
// 搜索
|
FootprintDelete: ApiRootUrl + 'footprint/delete', //删除足迹
|
||||||
SearchIndex: ApiRootUrl + 'search/index', //搜索页面数据
|
// 搜索
|
||||||
SearchHelper: ApiRootUrl + 'search/helper', //搜索帮助
|
SearchIndex: ApiRootUrl + 'search/index', //搜索页面数据
|
||||||
SearchClearHistory: ApiRootUrl + 'search/clearHistory', //搜索帮助
|
SearchHelper: ApiRootUrl + 'search/helper', //搜索帮助
|
||||||
ShowSettings: ApiRootUrl + 'settings/showSettings',
|
SearchClearHistory: ApiRootUrl + 'search/clearHistory', //搜索帮助
|
||||||
SaveSettings: ApiRootUrl + 'settings/save',
|
ShowSettings: ApiRootUrl + 'settings/showSettings',
|
||||||
SettingsDetail: ApiRootUrl + 'settings/userDetail',
|
SaveSettings: ApiRootUrl + 'settings/save',
|
||||||
GetBase64: ApiRootUrl + 'qrcode/getBase64', //获取商品详情二维码
|
SettingsDetail: ApiRootUrl + 'settings/userDetail',
|
||||||
|
UploadAvatar: ApiRootUrl + 'upload/uploadAvatar',
|
||||||
|
GetBase64: ApiRootUrl + 'qrcode/getBase64', //获取商品详情二维码
|
||||||
|
|
||||||
};
|
};
|
||||||
BIN
images/icon/nick.png
Normal file
BIN
images/icon/nick.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
@ -5,90 +5,92 @@ const user = require('../../services/user.js');
|
|||||||
const app = getApp()
|
const app = getApp()
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
},
|
},
|
||||||
onLoad: function (options) {
|
onLoad: function (options) {
|
||||||
|
|
||||||
},
|
},
|
||||||
onShow: function () {
|
onShow: function () {
|
||||||
let userInfo = wx.getStorageSync('userInfo');
|
let userInfo = wx.getStorageSync('userInfo');
|
||||||
if (userInfo != '') {
|
if (userInfo != '') {
|
||||||
wx.navigateBack();
|
wx.navigateBack();
|
||||||
|
};
|
||||||
|
},
|
||||||
|
// getUserInfo: function (e) {
|
||||||
|
// app.globalData.userInfo = e.detail.userInfo
|
||||||
|
// user.loginByWeixin().then(res => {
|
||||||
|
// app.globalData.userInfo = res.data.userInfo;
|
||||||
|
// app.globalData.token = res.data.token;
|
||||||
|
// let is_new = res.data.is_new;//服务器返回的数据;
|
||||||
|
// if (is_new == 0) {
|
||||||
|
// util.showErrorToast('您已经是老用户啦!');
|
||||||
|
// wx.navigateBack();
|
||||||
|
// }
|
||||||
|
// else if (is_new == 1) {
|
||||||
|
// wx.navigateBack();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }).catch((err) => { });
|
||||||
|
// },
|
||||||
|
|
||||||
|
getUserProfile: function () {
|
||||||
|
// wx.navigateTo({
|
||||||
|
// url: '/pages/app-auth/index',
|
||||||
|
// });
|
||||||
|
let that = this;
|
||||||
|
let code = '';
|
||||||
|
wx.login({
|
||||||
|
success: (res) => {
|
||||||
|
console.log(res)
|
||||||
|
code = res.code;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// 获取用户信息
|
||||||
|
wx.getUserProfile({
|
||||||
|
lang: 'zh_CN',
|
||||||
|
desc: '用户登录',
|
||||||
|
success: (res) => {
|
||||||
|
let loginParams = {
|
||||||
|
code: code,
|
||||||
|
app: 3,
|
||||||
|
encryptedData: res.encryptedData,
|
||||||
|
iv: res.iv,
|
||||||
|
rawData: res.rawData,
|
||||||
|
signature: res.signature
|
||||||
};
|
};
|
||||||
},
|
console.log(loginParams);
|
||||||
// getUserInfo: function (e) {
|
that.postLogin(loginParams);
|
||||||
// app.globalData.userInfo = e.detail.userInfo
|
},
|
||||||
// user.loginByWeixin().then(res => {
|
// 失败回调
|
||||||
// app.globalData.userInfo = res.data.userInfo;
|
fail: () => {
|
||||||
// app.globalData.token = res.data.token;
|
// 弹出错误
|
||||||
// let is_new = res.data.is_new;//服务器返回的数据;
|
App.showError('已拒绝小程序获取信息');
|
||||||
// if (is_new == 0) {
|
}
|
||||||
// util.showErrorToast('您已经是老用户啦!');
|
});
|
||||||
// wx.navigateBack();
|
},
|
||||||
// }
|
postLogin(info) {
|
||||||
// else if (is_new == 1) {
|
util.request(api.AuthLoginByWeixin, {
|
||||||
// wx.navigateBack();
|
info: info
|
||||||
// }
|
}, 'POST').then(function (res) {
|
||||||
|
console.log(res);
|
||||||
// }).catch((err) => { });
|
if (res.errno === 0) {
|
||||||
// },
|
wx.setStorageSync('userInfo', res.data.userInfo);
|
||||||
|
wx.setStorageSync('token', res.data.token);
|
||||||
getUserProfile: function () {
|
app.globalData.userInfo = res.data.userInfo;
|
||||||
// wx.navigateTo({
|
app.globalData.token = res.data.token;
|
||||||
// url: '/pages/app-auth/index',
|
let is_new = res.data.is_new; //服务器返回的数据;
|
||||||
// });
|
console.log(is_new);
|
||||||
let that = this;
|
if (is_new == 0) {
|
||||||
let code = '';
|
util.showErrorToast('您已经是老用户啦!');
|
||||||
wx.login({
|
wx.navigateBack();
|
||||||
success: (res) => {
|
} else if (is_new == 1) {
|
||||||
code = res.code;
|
wx.navigateBack();
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
// 获取用户信息
|
});
|
||||||
wx.getUserProfile({
|
},
|
||||||
lang: 'zh_CN',
|
goBack: function () {
|
||||||
desc: '用户登录',
|
wx.navigateBack();
|
||||||
success: (res) => {
|
}
|
||||||
let loginParams = {
|
|
||||||
code: code,
|
|
||||||
encryptedData: res.encryptedData,
|
|
||||||
iv: res.iv,
|
|
||||||
rawData: res.rawData,
|
|
||||||
signature: res.signature
|
|
||||||
};
|
|
||||||
console.log(loginParams);
|
|
||||||
that.postLogin(loginParams);
|
|
||||||
},
|
|
||||||
// 失败回调
|
|
||||||
fail: () => {
|
|
||||||
// 弹出错误
|
|
||||||
App.showError('已拒绝小程序获取信息');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
postLogin(info) {
|
|
||||||
util.request(api.AuthLoginByWeixin, {
|
|
||||||
info: info
|
|
||||||
}, 'POST').then(function (res) {
|
|
||||||
console.log(res);
|
|
||||||
if (res.errno === 0) {
|
|
||||||
wx.setStorageSync('userInfo', res.data.userInfo);
|
|
||||||
wx.setStorageSync('token', res.data.token);
|
|
||||||
app.globalData.userInfo = res.data.userInfo;
|
|
||||||
app.globalData.token = res.data.token;
|
|
||||||
let is_new = res.data.is_new; //服务器返回的数据;
|
|
||||||
console.log(is_new);
|
|
||||||
if (is_new == 0) {
|
|
||||||
util.showErrorToast('您已经是老用户啦!');
|
|
||||||
wx.navigateBack();
|
|
||||||
} else if (is_new == 1) {
|
|
||||||
wx.navigateBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
goBack: function () {
|
|
||||||
wx.navigateBack();
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
@ -1,16 +1,15 @@
|
|||||||
<view class="container">
|
<view class="container">
|
||||||
<view class='about-wrap'>
|
<view class='about-wrap'>
|
||||||
<view class='title'>海风小店</view>
|
<view class='title'>海风小店</view>
|
||||||
<view class='content'>
|
<view class='content'>
|
||||||
开源微信小程序商城
|
开源微信小程序商城
|
||||||
</view>
|
|
||||||
<view class="line"></view>
|
|
||||||
<view class="content">开发者:盛良</view>
|
|
||||||
<view class="content">微信:lookgxl</view>
|
|
||||||
<view class="line"></view>
|
|
||||||
<view class='content'>
|
|
||||||
更多信息访问:hiolabs.com
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
<!-- <ad unit-id="adunit-1776b4f8f2217197" ad-type="video" ad-theme="white"></ad> -->
|
<view class="img-wrap">
|
||||||
|
<image mode="aspectFill" class="code-img" src="https://www.qile.club/qrcode.jpg" show-menu-by-longpress="{{true}}"></image>
|
||||||
|
</view>
|
||||||
|
<view class='content'>
|
||||||
|
更多信息访问:qile.club
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<ad unit-id="adunit-1776b4f8f2217197" ad-type="video" ad-theme="white"></ad>
|
||||||
</view>
|
</view>
|
||||||
@ -14,7 +14,7 @@ page {
|
|||||||
|
|
||||||
.about-wrap {
|
.about-wrap {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
padding: 50rpx 40rpx;
|
padding: 0 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
@ -32,8 +32,19 @@ page {
|
|||||||
text-indent: 56rpx;
|
text-indent: 56rpx;
|
||||||
line-height: 50rpx;
|
line-height: 50rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.img-wrap{
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-img{
|
||||||
|
width: 550rpx;
|
||||||
|
height: 750rpx;
|
||||||
|
}
|
||||||
.line {
|
.line {
|
||||||
height: 1rpx;
|
height: 1rpx;
|
||||||
border-top: 1rpx solid #f1f1f1;
|
border-top: 1rpx solid #f1f1f1;
|
||||||
|
|||||||
@ -7,92 +7,125 @@ var user = require('../../../services/user.js');
|
|||||||
const app = getApp()
|
const app = getApp()
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
hasUserInfo: false,
|
hasUserInfo: false,
|
||||||
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
status: {},
|
||||||
status: {},
|
root: api.ApiRoot,
|
||||||
},
|
is_new: 0,
|
||||||
goProfile: function (e) {
|
root: api.ApiRoot
|
||||||
let res = util.loginNow();
|
},
|
||||||
if (res == true) {
|
goProfile: function (e) {
|
||||||
wx.navigateTo({
|
let res = util.loginNow();
|
||||||
url: '/pages/ucenter/settings/index',
|
if (res == true) {
|
||||||
});
|
wx.navigateTo({
|
||||||
}
|
url: '/pages/ucenter/settings/index',
|
||||||
},
|
});
|
||||||
toOrderListTap: function(event) {
|
}
|
||||||
let res = util.loginNow();
|
},
|
||||||
if (res == true) {
|
toOrderListTap: function (event) {
|
||||||
let showType = event.currentTarget.dataset.index;
|
let res = util.loginNow();
|
||||||
wx.setStorageSync('showType', showType);
|
if (res == true) {
|
||||||
wx.navigateTo({
|
let showType = event.currentTarget.dataset.index;
|
||||||
url: '/pages/ucenter/order-list/index?showType=' + showType,
|
wx.setStorageSync('showType', showType);
|
||||||
});
|
wx.navigateTo({
|
||||||
}
|
url: '/pages/ucenter/order-list/index?showType=' + showType,
|
||||||
},
|
});
|
||||||
toAddressList: function(e) {
|
}
|
||||||
let res = util.loginNow();
|
},
|
||||||
if (res == true) {
|
toAddressList: function (e) {
|
||||||
wx.navigateTo({
|
let res = util.loginNow();
|
||||||
url: '/pages/ucenter/address/index?type=0',
|
if (res == true) {
|
||||||
});
|
wx.navigateTo({
|
||||||
}
|
url: '/pages/ucenter/address/index?type=0',
|
||||||
},
|
});
|
||||||
toAbout: function () {
|
}
|
||||||
wx.navigateTo({
|
},
|
||||||
url: '/pages/ucenter/about/index',
|
toAbout: function () {
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '/pages/ucenter/about/index',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
toFootprint: function (e) {
|
||||||
|
let res = util.loginNow();
|
||||||
|
if (res == true) {
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '/pages/ucenter/footprint/index',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// goAuth: function (e) {
|
||||||
|
// wx.navigateTo({
|
||||||
|
// url: '/pages/app-auth/index',
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
goAuth() {
|
||||||
|
let code = '';
|
||||||
|
let that = this;
|
||||||
|
wx.login({
|
||||||
|
success: (res) => {
|
||||||
|
code = res.code;
|
||||||
|
that.postLogin(code)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
postLogin(code) {
|
||||||
|
let that = this;
|
||||||
|
util.request(api.AuthLoginByWeixin, {
|
||||||
|
code: code
|
||||||
|
}, 'POST').then(function (res) {
|
||||||
|
if (res.errno === 0) {
|
||||||
|
let userInfo = res.data.userInfo;
|
||||||
|
that.setData({
|
||||||
|
is_new: res.data.is_new,
|
||||||
|
userInfo: userInfo,
|
||||||
|
hasUserInfo: true
|
||||||
|
})
|
||||||
|
wx.setStorageSync('token', res.data.token);
|
||||||
|
wx.setStorageSync('userInfo', userInfo);
|
||||||
|
app.globalData.token = res.data.token;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onLoad: function (options) {
|
||||||
|
this.goAuth();
|
||||||
|
},
|
||||||
|
onShow: function () {
|
||||||
|
this.getOrderInfo();
|
||||||
|
this.getSettingsDetail();
|
||||||
|
wx.removeStorageSync('categoryId');
|
||||||
|
},
|
||||||
|
getSettingsDetail() {
|
||||||
|
let that = this;
|
||||||
|
util.request(api.SettingsDetail).then(function (res) {
|
||||||
|
console.log(res)
|
||||||
|
if (res.errno === 0) {
|
||||||
|
let userInfo = res.data;
|
||||||
|
console.log('userInfo')
|
||||||
|
console.log(userInfo)
|
||||||
|
// wx.setStorageSync('userInfo', userInfo);
|
||||||
|
that.setData({
|
||||||
|
userInfo: userInfo,
|
||||||
|
hasUserInfo: true
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
toFootprint: function(e) {
|
});
|
||||||
let res = util.loginNow();
|
},
|
||||||
if (res == true) {
|
onPullDownRefresh: function () {
|
||||||
wx.navigateTo({
|
wx.showNavigationBarLoading()
|
||||||
url: '/pages/ucenter/footprint/index',
|
this.getOrderInfo();
|
||||||
});
|
wx.hideNavigationBarLoading() //完成停止加载
|
||||||
}
|
wx.stopPullDownRefresh() //停止下拉刷新
|
||||||
},
|
},
|
||||||
goAuth: function(e) {
|
getOrderInfo: function (e) {
|
||||||
wx.navigateTo({
|
let that = this;
|
||||||
url: '/pages/app-auth/index',
|
util.request(api.OrderCountInfo).then(function (res) {
|
||||||
|
if (res.errno === 0) {
|
||||||
|
let status = res.data;
|
||||||
|
that.setData({
|
||||||
|
status: status
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
onLoad: function(options) {
|
});
|
||||||
},
|
},
|
||||||
onShow: function() {
|
|
||||||
let userInfo = wx.getStorageSync('userInfo');
|
|
||||||
if(userInfo == ''){
|
|
||||||
this.setData({
|
|
||||||
hasUserInfo: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
this.setData({
|
|
||||||
hasUserInfo: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.setData({
|
|
||||||
userInfo: userInfo,
|
|
||||||
});
|
|
||||||
this.getOrderInfo();
|
|
||||||
wx.removeStorageSync('categoryId');
|
|
||||||
},
|
|
||||||
|
|
||||||
onPullDownRefresh: function() {
|
|
||||||
wx.showNavigationBarLoading()
|
|
||||||
this.getOrderInfo();
|
|
||||||
wx.hideNavigationBarLoading() //完成停止加载
|
|
||||||
wx.stopPullDownRefresh() //停止下拉刷新
|
|
||||||
},
|
|
||||||
getOrderInfo: function(e) {
|
|
||||||
let that = this;
|
|
||||||
util.request(api.OrderCountInfo).then(function(res) {
|
|
||||||
if (res.errno === 0) {
|
|
||||||
let status = res.data;
|
|
||||||
that.setData({
|
|
||||||
status: status
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<view class="container">
|
<view class="container">
|
||||||
<view class="userinfo">
|
<view class="userinfo">
|
||||||
<view class='head-wrap' wx:if="{{hasUserInfo == 0}}" bindtap='goAuth'>
|
<view class='head-wrap' wx:if="{{hasUserInfo == false}}" bindtap='goAuth'>
|
||||||
<view class="no-login-avatar">
|
<view class="no-login-avatar">
|
||||||
<view class='no-avatar'>
|
<view class='no-avatar'>
|
||||||
<image class='avatar' src="/images/icon/default_avatar_big.png"></image>
|
<image class='avatar' src="/images/icon/default_avatar_big.png"></image>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
<view class='head-wrap' wx:else bindtap='goProfile'>
|
<view class='head-wrap' wx:else bindtap='goProfile'>
|
||||||
<view class="head-l">
|
<view class="head-l">
|
||||||
<view class='l'>
|
<view class='l'>
|
||||||
<image class='avatar' src="{{userInfo.avatar}}"></image>
|
<image class='avatar' src="{{root + userInfo.avatar}}"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class='r'>
|
<view class='r'>
|
||||||
<view class='t'>
|
<view class='t'>
|
||||||
|
|||||||
@ -1,75 +1,116 @@
|
|||||||
var util = require('../../../utils/util.js');
|
var util = require('../../../utils/util.js');
|
||||||
var api = require('../../../config/api.js');
|
var api = require('../../../config/api.js');
|
||||||
var app = getApp();
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
name: '',
|
name: '',
|
||||||
mobile: '',
|
nickName: '',
|
||||||
status: 0,
|
mobile: '',
|
||||||
},
|
avatarUrl: '/static/images/default_avatar.png',
|
||||||
mobilechange(e) {
|
hasAvatar: 0,
|
||||||
let mobile = e.detail.value;
|
root: api.ApiRoot
|
||||||
this.setData({
|
},
|
||||||
mobile: mobile,
|
onChooseAvatar(e) {
|
||||||
status: 0
|
const {
|
||||||
});
|
avatarUrl
|
||||||
if (util.testMobile(mobile)) {
|
} = e.detail
|
||||||
this.setData({
|
this.setData({
|
||||||
mobile: mobile,
|
avatarUrl,
|
||||||
status: 1
|
})
|
||||||
});
|
let that = this;
|
||||||
|
wx.uploadFile({
|
||||||
|
url: api.UploadAvatar,
|
||||||
|
filePath: avatarUrl,
|
||||||
|
name: 'upload_file',
|
||||||
|
formData: {
|
||||||
|
// 'userId': 'test'
|
||||||
|
},
|
||||||
|
success(res) {
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
let re = res.data
|
||||||
|
let echo = JSON.parse(re);
|
||||||
|
console.log(echo);
|
||||||
|
let data = echo.data;
|
||||||
|
let avatarUrl = data.fileUrl
|
||||||
|
console.log(avatarUrl)
|
||||||
|
that.setData({
|
||||||
|
avatarUrl: avatarUrl,
|
||||||
|
hasAvatar: 1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
bindinputName(event) {
|
})
|
||||||
let name = event.detail.value;
|
},
|
||||||
let mobile = this.data.mobile;
|
mobilechange(e) {
|
||||||
this.setData({
|
let mobile = e.detail.value;
|
||||||
name: name,
|
this.setData({
|
||||||
|
mobile: mobile,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
bindinputNickName(event) {
|
||||||
|
let nickName = event.detail.value;
|
||||||
|
this.setData({
|
||||||
|
nickName: nickName,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
bindinputName(event) {
|
||||||
|
let name = event.detail.value;
|
||||||
|
this.setData({
|
||||||
|
name: name,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getSettingsDetail() {
|
||||||
|
let that = this;
|
||||||
|
util.request(api.SettingsDetail).then(function (res) {
|
||||||
|
if (res.errno === 0) {
|
||||||
|
that.setData({
|
||||||
|
name: res.data.name,
|
||||||
|
mobile: res.data.mobile,
|
||||||
|
nickName: res.data.nickname,
|
||||||
|
hasAvatar: 0
|
||||||
});
|
});
|
||||||
if (util.testMobile(mobile)) {
|
if (res.data.avatar != '') {
|
||||||
this.setData({
|
that.setData({
|
||||||
status: 1
|
avatarUrl: res.data.avatar,
|
||||||
});
|
hasAvatar: 1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
getSettingsDetail() {
|
});
|
||||||
let that = this;
|
},
|
||||||
util.request(api.SettingsDetail).then(function(res) {
|
onLoad: function (options) {
|
||||||
if (res.errno === 0) {
|
this.getSettingsDetail();
|
||||||
that.setData({
|
},
|
||||||
name: res.data.name,
|
saveInfo() {
|
||||||
mobile: res.data.mobile,
|
let name = this.data.name;
|
||||||
});
|
let mobile = this.data.mobile;
|
||||||
if (res.data.name == '' || res.data.mobile == ''){
|
mobile = mobile.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
util.showErrorToast('请填写姓名和手机');
|
if (mobile != '') {
|
||||||
}
|
var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(16[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
|
||||||
}
|
if (mobile.length < 11) {
|
||||||
});
|
return util.showErrorToast('手机号码长度不对');
|
||||||
},
|
} else if (!myreg.test(mobile)) {
|
||||||
onLoad: function(options) {
|
return util.showErrorToast('手机号码有问题');
|
||||||
this.getSettingsDetail();
|
}
|
||||||
},
|
}
|
||||||
saveInfo() {
|
let avatar = this.data.avatarUrl;
|
||||||
let name = this.data.name;
|
let nickName = this.data.nickName;
|
||||||
let mobile = this.data.mobile;
|
nickName = nickName.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
let status = this.data.status;
|
if (nickName == '') {
|
||||||
if (name == '') {
|
util.showErrorToast('请输入昵称');
|
||||||
util.showErrorToast('请输入姓名');
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
console.log(avatar)
|
||||||
if (mobile == '') {
|
util.request(api.SaveSettings, {
|
||||||
util.showErrorToast('请输入手机号码');
|
name: name,
|
||||||
return false;
|
mobile: mobile,
|
||||||
}
|
nickName: nickName,
|
||||||
let that = this;
|
avatar: avatar,
|
||||||
util.request(api.SaveSettings, {
|
}, 'POST').then(function (res) {
|
||||||
name: name,
|
if (res.errno === 0) {
|
||||||
mobile: mobile,
|
util.showErrorToast('保存成功');
|
||||||
}, 'POST').then(function(res) {
|
wx.navigateBack()
|
||||||
if (res.errno === 0) {
|
}
|
||||||
util.showErrorToast('保存成功');
|
});
|
||||||
wx.navigateBack()
|
},
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
@ -1,16 +1,22 @@
|
|||||||
<view class="container">
|
<view class="container">
|
||||||
<view class='edit-container'>
|
<button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
|
||||||
<view class="a-item">
|
<image class="avatar" src="{{root + avatarUrl}}"></image>
|
||||||
<image class="icon" src="/images/icon/receiver.png"></image>
|
</button>
|
||||||
<input class='a-input' bindblur="bindinputName" placeholder='真实姓名' value="{{name}}"></input>
|
<view class='edit-container'>
|
||||||
</view>
|
<view class="a-item">
|
||||||
<view class="a-item">
|
<image class="icon" src="/images/icon/nick.png"></image>
|
||||||
<image class="icon" src="/images/icon/mobile.png"></image>
|
<input type="nickname" class="a-input" bindblur="bindinputNickName" value="{{nickName}}" placeholder="请输入昵称" />
|
||||||
<input class='a-input' bindblur="mobilechange" value="{{mobile}}" placeholder='手机号码'></input>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
<view class='wrap-btn'>
|
<view class="a-item">
|
||||||
<view wx:if="{{status == 0}}" class="btn-wrap disable}}">保存</view>
|
<image class="icon" src="/images/icon/receiver.png"></image>
|
||||||
<view wx:else class="btn-wrap active" bindtap='saveInfo'>保存</view>
|
<input class='a-input' bindblur="bindinputName" placeholder='请输入姓名' value="{{name}}"></input>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
<view class="a-item">
|
||||||
|
<image class="icon" src="/images/icon/mobile.png"></image>
|
||||||
|
<input class='a-input' bindblur="mobilechange" value="{{mobile}}" placeholder='请输入手机'></input>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class='wrap-btn'>
|
||||||
|
<view class="btn-wrap active" bindtap='saveInfo'>保存</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@ -1,18 +1,38 @@
|
|||||||
page {
|
page {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
background-color: #f8f8f8;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.avatar-wrapper {
|
||||||
|
padding: 0;
|
||||||
|
width: 56px !important;
|
||||||
|
margin-top: 40px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-tip{
|
||||||
|
text-align: center;
|
||||||
|
font-size: 24rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
color: #aaa;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
.avatar {
|
||||||
|
display: block;
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
}
|
||||||
.container {
|
.container {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
/* align-items: stretch; */
|
/* align-items: stretch; */
|
||||||
background: #f8f8f8;
|
background: #fff;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.edit-container {
|
.edit-container {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
margin-top: 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.a-item {
|
.a-item {
|
||||||
|
|||||||
@ -238,10 +238,19 @@ function sentRes(url, data, method, fn) {
|
|||||||
function loginNow() {
|
function loginNow() {
|
||||||
let userInfo = wx.getStorageSync('userInfo');
|
let userInfo = wx.getStorageSync('userInfo');
|
||||||
if (userInfo == '') {
|
if (userInfo == '') {
|
||||||
wx.navigateTo({
|
wx.login({
|
||||||
url: '/pages/app-auth/index',
|
success: (res) => {
|
||||||
});
|
request(api.AuthLoginByWeixin, {
|
||||||
return false;
|
code: res.code
|
||||||
|
}, 'POST').then(function (res) {
|
||||||
|
if (res.errno === 0) {
|
||||||
|
let userInfo = res.data.userInfo;
|
||||||
|
wx.setStorageSync('token', res.data.token);
|
||||||
|
wx.setStorageSync('userInfo', userInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user