更新了微信小程序获取头像和昵称的接口,修复了ios付款后订阅消息一闪而过的bug,还有其他一些小问题。

This commit is contained in:
iamdarcy 2021-07-04 13:51:13 +08:00
parent eed38ed482
commit 353cad572e
21 changed files with 206 additions and 106 deletions

View File

@ -1,5 +1,6 @@
// const ApiRootUrl = 'http://localhost:8360/api/';
const ApiRootUrl = 'https://www.hiolabs.com/api/';
// const ApiRootUrl = 'http://192.168.0.108:8360/api/';
const ApiRootUrl = 'https://www.guxiaoling.com:8466/api/';
module.exports = {
// 登录

BIN
images/icon/addr-line.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -27,7 +27,7 @@
</template>
<template name="wxParseImg">
<image class="{{item.classStr}} wxParse-{{item.tag}}" data-from="{{item.from}}" data-src="{{item.attr.src}}" data-idx="{{item.imgIndex}}" src="{{item.attr.src}}" mode="aspectFit" bindload="wxParseImgLoad" bindtap="wxParseImgTap" style="width:{{item.width}}px;height:{{item.height}}px;{{item.attr.style}}" />
<image class="{{item.classStr}} wxParse-{{item.tag}}" data-from="{{item.from}}" data-src="{{item.attr.src}}" data-idx="{{item.imgIndex}}" src="{{item.attr.src}}" mode="widthFix" bindload="wxParseImgLoad" bindtap="wxParseImgTap" style="width:{{item.width}}px;height:{{item.height}}px;{{item.attr.style}}" />
</template>
<template name="WxEmojiView">

View File

@ -6,10 +6,10 @@ const app = getApp()
Page({
data: {
},
onLoad: function (options) {
},
onShow: function () {
let userInfo = wx.getStorageSync('userInfo');
@ -17,23 +17,78 @@ Page({
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();
}
// 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) => { });
// }).catch((err) => { });
// },
getUserProfile: function () {
// wx.navigateTo({
// url: '/pages/app-auth/index',
// });
let that = this;
let code = '';
wx.login({
success: (res) => {
code = res.code;
},
});
// 获取用户信息
wx.getUserProfile({
lang: 'zh_CN',
desc: '用户登录',
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('已拒绝小程序获取信息');
}
});
},
goBack:function(){
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();
}
})

View File

@ -5,9 +5,14 @@
<view class='logo-name'>海风小店</view>
<view class='intro'>开源微信小程序商城</view>
<view class='login'>请完成微信授权以继续使用</view>
<button class='btn-login' open-type="getUserInfo" bindgetuserinfo='getUserInfo'>
<!-- <button class='btn-login' open-type="getUserInfo" bindgetuserinfo='getUserInfo'>
<image src='/images/icon/weixin-w.png' class='img-w'></image>
<view class='text'>微信快捷登录</view>
</button> -->
<button class='btn-login' bindtap='getUserProfile'>
<view class='img-w'></view>
<view class='text'>微信快捷登录</view>
</button>
<view class="cancel" bindtap="goBack">取消</view>
</view>

View File

@ -30,6 +30,15 @@ Page({
this.getCartList();
this.getCartNum();
wx.removeStorageSync('categoryId');
},
goGoodsDetail(e){
let goodsId = e.currentTarget.dataset.goodsid;
wx.navigateTo({
url: '/pages/goods/goods?id='+goodsId,
})
},
nothing:function(){
},
onPullDownRefresh: function() {
wx.showNavigationBarLoading()

View File

@ -8,8 +8,8 @@
</view>
<image src="/images/icon/gou-gray.png" wx:else class="checkbox"></image>
<view class="goods-info">
<navigator class="goods-url" hover-class="none" url="/pages/goods/goods?id={{item.goods_id}}">
<view class="img-box">
<view class="goods-url">
<view class="img-box" bindtap="goGoodsDetail" data-goodsid="{{item.goods_id}}">
<image src="{{item.list_pic_url}}" class="img" />
</view>
<view class="text-box">
@ -18,14 +18,14 @@
<view class="goods-price">
<view class='price-now'>¥{{item.retail_price}}</view>
</view>
<view class="selnum" wx:if="{{item.number > 0 && item.is_on_sale == 1}}">
<view class="selnum" catchtap="nothing" wx:if="{{item.number > 0 && item.is_on_sale == 1}}">
<view data-item-index="{{index}}" class="cut" catchtap="cutNumber">-</view>
<input value="{{item.number}}" class="number" disabled="true" type="number" />
<view data-item-index="{{index}}" class="add" catchtap="addNumber" disabled='{{disabled}}'>+</view>
</view>
<view wx:else class="out-stock">暂时缺货</view>
</view>
</navigator>
</view>
</view>
</view>
<view class="delete-btn" data-item-index="{{index}}" catchtap="deleteGoods">

View File

@ -231,7 +231,7 @@ button::after {
border: none;
}
.goods-info .text-box .selnum {
/* .goods-info .text-box .selnum {
width: 146rpx;
height: 52rpx;
display: flex;
@ -240,8 +240,21 @@ button::after {
position: absolute;
right: 30rpx;
bottom: 0;
} */
.goods-info .text-box .selnum {
width: 146rpx;
height: 52rpx;
padding: 50rpx 0 0 100rpx;
display: flex;
justify-content: space-around;
align-items: center;
position: absolute;
right: 30rpx;
bottom: 0;
}
.selnum .cut {
width: 46rpx;
height: 46rpx;
@ -345,7 +358,6 @@ button::after {
width: 510rpx;
/* justify-content: space-between; */
line-height: 100rpx;
padding: 0 30rpx 0 0;
font-size: 28rpx;
box-sizing: border-box;
}
@ -367,5 +379,5 @@ button::after {
.settle-box .total {
color: #ff3456;
float: left;
margin-left: 30rpx;
margin-left: 20rpx;
}

View File

@ -125,7 +125,9 @@ Page({
galleryImages: galleryImages,
loading:1
});
WxParse.wxParse('goodsDetail', 'html', res.data.info.goods_desc, that);
setTimeout(() => {
WxParse.wxParse('goodsDetail', 'html', res.data.info.goods_desc, that);
}, 1000);
wx.setStorageSync('goodsImage', res.data.info.https_pic_url);
}
else{
@ -392,7 +394,6 @@ Page({
alone_text: '加入购物车'
})
} else {
//提示选择完整规格
if (!this.isCheckedAllSpec()) {
wx.showToast({
@ -401,7 +402,6 @@ Page({
});
return false;
}
//根据选中的规格判断是否有对应的sku信息
let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey());
if (!checkedProductArray || checkedProductArray.length <= 0) {
@ -422,6 +422,10 @@ Page({
});
return false;
}
wx.showLoading({
title: '',
mask:true
})
util.request(api.CartAdd, {
addType: 0,
goodsId: this.data.id,
@ -450,7 +454,7 @@ Page({
title: _res.errmsg,
});
}
wx.hideLoading()
});
}
},
@ -500,6 +504,10 @@ Page({
return false;
}
//添加到购物车
wx.showLoading({
title: '',
mask:true
})
util.request(api.CartAdd, {
addType: 1, // 0正常加入购物车1:立即购买2:再来一单
goodsId: this.data.id,
@ -508,6 +516,7 @@ Page({
}, "POST")
.then(function(res) {
let _res = res;
wx.hideLoading()
if (_res.errno == 0) {
let id = that.data.id;
wx.navigateTo({

View File

@ -55,6 +55,7 @@
</view>
<view class='details-wrap'>
<view class="title">商品详情</view>
<!-- <ad unit-id="adunit-2d961509e15e91d7" ad-type="grid" grid-opacity="0.8" grid-count="5" ad-theme="white"></ad> -->
<view class="show">
<view class='details-image-wrap'>
<import src="../../lib/wxParse/wxParse.wxml" />

View File

@ -14,7 +14,9 @@
width: 100%;
}
.ad-video{
width: 100%;
}
.loading {
width: 100%;
height: 100%;

View File

@ -12,14 +12,27 @@ Page({
showChannel: 0,
showBanner: 0,
showBannerImg: 0,
goodsCount: 0,
banner: [],
index_banner_img: 0,
userInfo: {},
imgurl: '',
sysHeight: 0,
loading: 0,
autoplay:true
autoplay:true,
showContact:1,
},
onPageScroll: function (e) {
let scrollTop = e.scrollTop;
let that = this;
if (scrollTop >= 2000) {
that.setData({
showContact: 0
})
} else {
that.setData({
showContact: 1
})
}
},
onHide:function(){
this.setData({
@ -38,14 +51,6 @@ Page({
url: '/pages/category/index',
})
},
getCatalog: function () {
let that = this;
util.request(api.GoodsCount).then(function (res) {
that.setData({
goodsCount: res.data.goodsCount
});
});
},
handleTap: function (event) {
//阻止冒泡
},
@ -73,17 +78,25 @@ Page({
notice: res.data.notice,
loading: 1,
});
let cartGoodsCount = '';
if (res.data.cartCount == 0) {
wx.removeTabBarBadge({
index: 2,
})
} else {
cartGoodsCount = res.data.cartCount + '';
wx.setTabBarBadge({
index: 2,
text: cartGoodsCount
})
}
}
});
},
onLoad: function (options) {
let systemInfo = wx.getStorageSync('systemInfo');
var scene = decodeURIComponent(options.scene);
this.getCatalog();
this.getChannelShowInfo();
},
onShow: function () {
this.getCartNum();
this.getChannelShowInfo();
this.getIndexData();
var that = this;
let userInfo = wx.getStorageSync('userInfo');
@ -100,24 +113,6 @@ Page({
});
wx.removeStorageSync('categoryId');
},
getCartNum: function () {
util.request(api.CartGoodsCount).then(function (res) {
if (res.errno === 0) {
let cartGoodsCount = '';
if (res.data.cartTotal.goodsCount == 0) {
wx.removeTabBarBadge({
index: 2,
})
} else {
cartGoodsCount = res.data.cartTotal.goodsCount + '';
wx.setTabBarBadge({
index: 2,
text: cartGoodsCount
})
}
}
});
},
getChannelShowInfo: function (e) {
let that = this;
util.request(api.ShowSettings).then(function (res) {

View File

@ -1,5 +1,5 @@
<view class="container" wx:if="{{loading == 1}}">
<view class='contact-wrap'>
<view class='contact-wrap' wx:if="{{showContact == 1}}">
<button class="contact-btn" session-from='{"nickName":"{{userInfo.nickname}}","avatarUrl":"{{userInfo.avatar}}"}' open-type="contact">
<image class='icon' src='/images/icon/contact.png'></image>
<view class='text'>客服</view>
@ -7,7 +7,7 @@
</view>
<view class="search" bindtap="goSearch">
<image class="icon" src="/images/icon/search.png"></image>
<text class="txt">搜索, 共{{goodsCount}}款好物</text>
<text class="txt">搜索,发现更多好物</text>
</view>
<view class='banner-wrap' wx:if="{{show_banner && banner.length > 0}}">
<swiper class="banner" indicator-dots="true" autoplay="{{autoplay}}" interval="3000" duration="1000" >
@ -34,6 +34,7 @@
</swiper-item>
</swiper>
</view>
<!-- <ad unit-id="adunit-c755904541658aa1" ad-type="grid" grid-opacity="0.8" grid-count="5" ad-theme="white"></ad> -->
<swiper class="catalog-wrap" indicator-dots="{{false}}" indicator-color="#dedede" indicator-active-color="#e00000" wx:if="{{show_channel}}">
<swiper-item class="first">
<view wx:for="{{channel}}" wx:if="{{item.sort_order < 7}}" wx:key="id" class='icon-navi' data-cateid="{{item.id}}" bindtap="goCategory">
@ -95,6 +96,7 @@
<view class="more-category" data-cateid="{{item.id}}" bindtap="goCategory">点击查看更多{{item.name}}</view>
</view>
</view>
<!-- <ad unit-id="adunit-b6fcdb43b7913591"></ad> -->
<view class="no-more-goods ">没有更多商品啦</view>
</view>
<view class="loading" style="height:{{sysHeight}}px" wx:else>

View File

@ -25,4 +25,5 @@
</view>
<view class='btn-go-order' bindtap="toOrderListPage">返回我的页面</view>
</view>
<!-- <ad unit-id="adunit-f572025851df64b3" ad-type="video" ad-theme="white"></ad> -->
</view>

View File

@ -24,9 +24,21 @@ Page({
});
},
toIndex: function() {
wx.switchTab({
url: '/pages/index/index'
});
wx.requestSubscribeMessage({
tmplIds: ['w6AMCJ0FI2LqjCjWPIrpnVWTsFgnlNlmCf9TTDmG6_U'],
success(res) {
console.log(res);
wx.switchTab({
url: '/pages/index/index'
});
},
fail(err) {
console.log(err);
wx.switchTab({
url: '/pages/index/index'
});
}
})
},
payOrder() {
pay.payOrder(parseInt(this.data.orderId)).then(res => {

View File

@ -28,4 +28,5 @@
</view>
<view class='btn-go-order' bindtap="toOrderListPage">返回我的页面</view>
</view>
<!-- <ad class="ad-video" unit-id="adunit-f572025851df64b3" ad-type="video" ad-theme="white"></ad> -->
</view>

View File

@ -8,7 +8,9 @@ page {
align-items: flex-start;
overflow-x: hidden;
}
.ad-video{
width: 100%;
}
.result-wrap {
width: 100%;
height: 40%;

View File

@ -12,4 +12,5 @@
更多信息访问hiolabs.com
</view>
</view>
<!-- <ad unit-id="adunit-1776b4f8f2217197" ad-type="video" ad-theme="white"></ad> -->
</view>

View File

@ -24,6 +24,7 @@
</view>
</view>
</view>
<!-- <ad unit-id="adunit-89ae0a0b6860dc9f" ad-type="grid" grid-opacity="0.8" grid-count="5" ad-theme="white"></ad> -->
<view class="order-container">
<view class='header' data-index='0' bindtap='toOrderListTap'>
<view class='top-title'>
@ -103,7 +104,7 @@
</view>
</view>
<view class="company">
<view class="c-wrap">
<view class="c-wrap" bindtap="getOrderInfo">
<view class="text">海风小店</view>
<view class="line"></view>
</view>

View File

@ -19,15 +19,6 @@ function payOrder(orderId) {
'signType': payParam.signType,
'paySign': payParam.paySign,
'success': function(res) {
wx.requestSubscribeMessage({
tmplIds: ['w6AMCJ0FI2LqjCjWPIrpnVWTsFgnlNlmCf9TTDmG6_U'],
success(res) {
console.log(res);
},
fail(err) {
console.log(err);
}
})
resolve(res);
},
'fail': function(res) {

View File

@ -74,7 +74,7 @@ function request(url, data = {}, method = "GET") {
method: method,
header: {
'Content-Type': 'application/json',
'X-Nideshop-Token': wx.getStorageSync('token')
'X-Hioshop-Token': wx.getStorageSync('token')
},
success: function(res) {
if (res.statusCode == 200) {
@ -82,30 +82,30 @@ function request(url, data = {}, method = "GET") {
if (res.data.errno == 401) {
//需要登录后才可以操作
let code = null;
return login().then((res) => {
code = res.code;
return getUserInfo();
}).then((userInfo) => {
//登录远程服务器
request(api.AuthLoginByWeixin, {
code: code,
userInfo: userInfo
}, 'POST').then(res => {
if (res.errno === 0) {
//存储用户信息
wx.setStorageSync('userInfo', res.data.userInfo);
wx.setStorageSync('token', res.data.token);
resolve(res);
} else {
reject(res);
}
}).catch((err) => {
reject(err);
});
}).catch((err) => {
reject(err);
})
// let code = null;
// return login().then((res) => {
// code = res.code;
// return getUserInfo();
// }).then((userInfo) => {
// //登录远程服务器
// request(api.AuthLoginByWeixin, {
// code: code,
// userInfo: userInfo
// }, 'POST').then(res => {
// if (res.errno === 0) {
// //存储用户信息
// wx.setStorageSync('userInfo', res.data.userInfo);
// wx.setStorageSync('token', res.data.token);
// resolve(res);
// } else {
// reject(res);
// }
// }).catch((err) => {
// reject(err);
// });
// }).catch((err) => {
// reject(err);
// })
} else {
resolve(res.data);
}