This commit is contained in:
GaoHao
2024-08-09 10:34:15 +08:00
9 changed files with 243 additions and 140 deletions

61
App.vue
View File

@@ -1,7 +1,7 @@
<template> <template>
<button v-show="false" open-type="getPhoneNumber" @getphonenumber="userlogin"> </button>
</template> </template>
<script> <script>
import Api from '@/common/js/api.js'
export default { export default {
onLaunch: function() { onLaunch: function() {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
@@ -10,9 +10,42 @@
uni.cache.set('NAME', '零点八零'); uni.cache.set('NAME', '零点八零');
this.userlogin() this.userlogin()
}, },
onLoad() {}, onLoad() {
},
onShow: function() { onShow: function() {
this.$store.dispatch("HeightActions"); //获取随时获取页面的高度 this.$store.dispatch("HeightActions"); //获取随时获取页面的高度
// #ifdef MP-WEIXIN
// 当向小程序后台请求完新版本信息会进行回调。res: {hasUpdate: true, version: 1.0.0}
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) { // 有更新
uni.showLoading({
title: '更新中...'
}); // 开始下载前显示Loading
}
});
// 当新版本下载完成,会进行回调
updateManager.onUpdateReady(function() {
uni.hideLoading(); // 关闭 Loading
uni.showModal({ // 弹确认框(强制更新)
title: '更新提示',
content: '更新完毕,是否重启?',
success: function(res) {
if (res.confirm) {
updateManager.applyUpdate(); // 强制小程序重启并使用新版本。
}
}
})
});
// 当新版本下载失败,会进行回调
updateManager.onUpdateFailed(function() {
uni.hideLoading(); // 关闭 Loading
uni.showToast({
title: '更新失败,稍后再试...',
icon: "error"
});
});
// #endif
}, },
onHide: function() { onHide: function() {
@@ -21,7 +54,29 @@
methods: { methods: {
userlogin() { userlogin() {
if (!uni.cache.get('token')) { if (!uni.cache.get('token')) {
this.$store.dispatch("loginEvent"); //获取shapid uni.login({
provider: 'weixin',
success: (data) => {
uni.getUserInfo({
provider: 'weixin',
success: async (infoRes) => {
uni.cache.set('weixincode', data.code);
let res = await Api.userwxlogin({
code: uni.cache.get('weixincode'), //临时登录凭证
rawData: infoRes.rawData,
})
if (res.code == 0) {
uni.cache.set('token', res.data.token);
uni.cache.set('miniAppOpenId', res.data.userInfo
.miniAppOpenId)
uni.cache.set('userInfo', res.data.userInfo);
this.$isResolve()
}
},
fail: (err) => {}
});
},
})
} }
} }
} }

View File

@@ -166,7 +166,7 @@ export default {
return uni.api.get("/product/queryShopIdByTableCode", data); return uni.api.get("/product/queryShopIdByTableCode", data);
}, },
geocodelocation(data) { //根据经纬度获取信息 geocodelocation(data) { //根据经纬度获取信息
return uni.api.get("/location/geocode", data); return uni.api.get("/location/geocode", data, false);
}, },
// 修改头像和昵称 // 修改头像和昵称
upUserInfo(data) { upUserInfo(data) {

View File

@@ -104,19 +104,18 @@ async function request(options) {
if (res.code != 0) { if (res.code != 0) {
console.log(options) console.log(options)
if (res.code == -4) { if (res.code == -4) {
// uni.showToast({ uni.showToast({
// title: '', title: res.message || res.msg,
// // title: res.message || res.msg, icon: "none",
// icon: "none", success: () => {
// success: () => { // setTimeout(res => {
// setTimeout(res => { // store.dispatch("loginEvent"); //获取shapid
// store.dispatch("loginEvent"); //获取shapid // }, 1000)
// }, 1000) }
// } })
// }) // setTimeout(res => {
setTimeout(res => { // store.dispatch("loginEvent"); //获取shapid
store.dispatch("loginEvent"); //获取shapid // }, 1000)
}, 1000)
} else if (res.code == 482) { } else if (res.code == 482) {
let nowTime = new Date() / 1000 | 0 let nowTime = new Date() / 1000 | 0
let offset = parseInt(res.data.message) - parseInt(nowTime); let offset = parseInt(res.data.message) - parseInt(nowTime);

View File

@@ -23,6 +23,10 @@ uni.$u.config.unit = 'rpx'
Vue.prototype.useStorage = useStorage Vue.prototype.useStorage = useStorage
Vue.prototype.api = Api; Vue.prototype.api = Api;
Vue.prototype.shop = Shop; Vue.prototype.shop = Shop;
Vue.prototype.$onLaunched = new Promise(resolve => {
Vue.prototype.$isResolve = resolve
})
// #ifdef VUE3 // #ifdef VUE3
import { import {
createSSRApp createSSRApp

View File

@@ -87,8 +87,9 @@
url: '/pages/member/activatedmemberone?shopId=' + uni.cache.get('shopUser') url: '/pages/member/activatedmemberone?shopId=' + uni.cache.get('shopUser')
}) })
} else { } else {
uni.pro.navigateTo('member/memberdetails', { uni.pro.navigateTo('member/index', {
shopId_id: uni.cache.get('shopUser'), shopId: uni.cache.get('shopUser'),
type: 'index',
}) })
} }
} else { } else {

View File

@@ -41,7 +41,8 @@
this.switchdata = false this.switchdata = false
uni.cache.set('userInfo', resdata .data); uni.cache.set('userInfo', resdata .data);
uni.pro.redirectTo('/pages/member/index', { uni.pro.redirectTo('/pages/member/index', {
shopId: uni.cache.get('shopUser') shopId: this.shopId,
type: 'index'
}) })
} }

View File

@@ -67,17 +67,94 @@
} }
}, },
onLoad(e) { async onLoad(e) {
this.shopId = e.shopId console.log(e)
if (e.type == 'list') { //从列表进来的 // if ( e.type == 'list' || e.type == 'index') {
this.paygetShopByMember(e.shopId) // this.shopId = e.shopId;
} else { // this.init();
this.paygetShopByMember(e.shopId) // }
if (e.q) {
this.shopId = this.getQueryString(decodeURIComponent(e.q), 'shopId')
this.tokenShow = false;
// 等待登录结果返回
if (!uni.cache.get('token')) {
await this.$onLaunched;
}
this.init();
} else{
this.shopId = e.shopId;
this.init();
} }
this.paygetActive(e.shopId) //列表 console.log(this.shopId)
}, },
methods: { methods: {
async init() {
let res = await this.api.shopUserInfo({
"shopId": this.shopId,
"userId": uni.cache.get('userInfo').id,
})
if (res.code == 0) {
this.usershopUserinfo = res.data
}
if ( this.usershopUserinfo.isVip == 0 ) {
this.memberOpen = true;
return;
}
this.paygetShopByMember(this.shopId)
this.paygetActive()
},
memberCancel () {
let pages = getCurrentPages()
if ( pages.length > 1) {
uni.navigateBack()
} else {
uni.exitMiniProgram({
success: function () {
console.log('退出成功');
},
fail: function () {
console.log('退出失败');
}
});
}
},
sumbit(d) {
if (d.detail.iv) {
uni.login({
provider: 'weixin',
success: async (data) => {
let res = await this.api.userwxlogins({
code: data.code,
encryptedData: d.detail.encryptedData,
iv: d.detail.iv,
shopId: this.shopId
})
if (res.code == 0) {
let resdata = await this.api.loginwxuserInfo({
userId: uni.cache.get('userInfo').id
})
if (resdata.code == 0) {
uni.cache.set('userInfo', resdata .data);
this.memberOpen = false
this.paygetShopByMember(this.shopId)
this.paygetActive()
}
}
}
})
}
},
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
},
async paygetShopByMember(w) { async paygetShopByMember(w) {
let res = await this.api.paygetShopByMember({ let res = await this.api.paygetShopByMember({
page: 1, page: 1,
@@ -93,6 +170,7 @@
page: 1, page: 1,
pageSize: 10 pageSize: 10
}) })
try { try {
this.listdata = res.data.list this.listdata = res.data.list
this.amount = res.data.list[0].minNum this.amount = res.data.list[0].minNum
@@ -138,9 +216,19 @@
title: "支付成功" title: "支付成功"
}) })
uni.hideLoading() uni.hideLoading()
setTimeout(res => { let pages = getCurrentPages()
uni.navigateBack() if ( pages.length > 1) {
}, 500) setTimeout(res => {
uni.navigateBack()
}, 500)
} else {
setTimeout(res => {
uni.switchTab({
url: '/pages/index/index'
})
}, 500)
}
}, },
fail: (res) => { fail: (res) => {
uni.hideLoading() uni.hideLoading()

View File

@@ -110,10 +110,11 @@
<!-- ?x-oss-process=image/resize,m_lfit,w_200,h_200,limit_90 --> <!-- ?x-oss-process=image/resize,m_lfit,w_200,h_200,limit_90 -->
<view class="goods" @click="clickspecifications(item1,index,index1)" <view class="goods" @click="clickspecifications(item1,index,index1)"
v-for="(item1,index1) in item.products" :key="index1"> v-for="(item1,index1) in item.products" :key="index1">
<image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true" <image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true"
@load="imageLoaded(item1,index,index1)" @load="imageLoaded(item1,index,index1)"
:src="`${item1.coverImg}${!item1.imgLoad?'?x-oss-process=image/resize,m_lfit,w_300,h_300':''}`" mode="aspectFill"></image> :src="`${item1.coverImg}${!item1.imgLoad?'?x-oss-process=image/resize,m_lfit,w_300,h_300':''}`"
<!-- <image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true" mode="aspectFill"></image>
<!-- <image class="goodsImg" v-if="item1.coverImg!=null" :lazy-load="true"
:src="`${item1.coverImg}`" mode="aspectFill"></image> --> :src="`${item1.coverImg}`" mode="aspectFill"></image> -->
<image class="goodsImg" src="@/static/1.gif" mode="" v-else :lazy-load="true"></image> <image class="goodsImg" src="@/static/1.gif" mode="" v-else :lazy-load="true"></image>
<view v-if="item.name=='热销'" class="topSort" :class="'c'+(index1+1)">TOP{{index1+1}} <view v-if="item.name=='热销'" class="topSort" :class="'c'+(index1+1)">TOP{{index1+1}}
@@ -277,7 +278,7 @@
<view class="shop_sku_box_name"> <view class="shop_sku_box_name">
{{item.name}} {{item.name}}
</view> </view>
<view class="flex-start" > <view class="flex-start">
<view class="shop_sku_box_item" v-for="(item1,index1) in item.children" :key="index1" <view class="shop_sku_box_item" v-for="(item1,index1) in item.children" :key="index1"
@click="morloe(item1,index,index1,item)" :style="{color:!item1.isGrounding?'#999':''}" @click="morloe(item1,index,index1,item)" :style="{color:!item1.isGrounding?'#999':''}"
:class=" item.start == index1 ?'shop_sku_box_item_selected':''"> :class=" item.start == index1 ?'shop_sku_box_item_selected':''">
@@ -389,15 +390,6 @@
this.$store.getters.is_BarHeight.customBar) this.$store.getters.is_BarHeight.customBar)
} }
}, },
onReady() {
// setTimeout(() => {
// uni.getSystemInfo({
// success: (data) => {
// this.scrollHeight = data.windowHeight
// }
// })
// }, 100);
},
onLoad(e) { onLoad(e) {
if (e.q) { if (e.q) {
this.tableCode = this.getQueryString(decodeURIComponent(e.q), 'code') this.tableCode = this.getQueryString(decodeURIComponent(e.q), 'code')
@@ -417,7 +409,7 @@
uni.$off('message') uni.$off('message')
this.fixedtrue = true this.fixedtrue = true
}, },
onShow() { async onShow() {
let _this = this; let _this = this;
this.orderdetailFlag = true; this.orderdetailFlag = true;
uni.pageScrollTo({ uni.pageScrollTo({
@@ -425,37 +417,10 @@
duration: 0 duration: 0
}); });
if (!uni.cache.get('token')) { if (!uni.cache.get('token')) {
uni.login({ await this.$onLaunched;
provider: 'weixin',
success: async (data) => {
try {
uni.getUserInfo({
provider: 'weixin',
success: async (infoRes) => {
uni.cache.set('weixincode', data.code);
let res = await this.api.userwxlogin({
code: uni.cache.get('weixincode'), //临时登录凭证
rawData: infoRes.rawData
})
if (res.code == 0) {
uni.cache.set('token', res.data.token);
uni.cache.set('miniAppOpenId', res.data.userInfo
.miniAppOpenId)
uni.cache.set('userInfo', res.data.userInfo);
uni.$on('message', this.getMessage)
_this.getLocation()
}
},
fail: (err) => {}
});
} catch (e) {}
}
});
} else {
uni.$on('message', this.getMessage)
_this.getLocation()
} }
uni.$on('message', this.getMessage)
_this.getLocation()
}, },
methods: { methods: {
navigateBacknav() { navigateBacknav() {
@@ -481,53 +446,40 @@
"type": "connect", "type": "connect",
}) })
}, },
/** /**
* 获取定位 * 获取定位
*/ */
getLocation () { getLocation() {
uni.getLocation({ try {
type: 'wgs84', uni.getLocation({
success: async (res) => { type: 'wgs84',
let successres = await this.api.geocodelocation({ success: async (res) => {
lng: res.longitude, let successres = await this.api.geocodelocation({
lat: res.latitude,
})
if (successres.code == 0) {
let datastorage = {
country: successres.data.addressComponent.country, // "中国"
province: successres.data.addressComponent.province, //province: "陕西省"
address: successres.data.addressComponent.city, //district: "西安市"
district: successres.data.addressComponent.district, //district: "未央区"
lng: res.longitude, lng: res.longitude,
lat: res.latitude, lat: res.latitude,
})
if (successres.code == 0) {
let datastorage = {
country: successres.data.addressComponent.country, // "中国"
province: successres.data.addressComponent.province, //province: "陕西省"
address: successres.data.addressComponent.city, //district: "西安市"
district: successres.data.addressComponent.district, //district: "未央区"
lng: res.longitude,
lat: res.latitude,
}
uni.cache.set('getLocationstorage', datastorage);
this.productqueryShop();
} }
uni.cache.set('getLocationstorage', datastorage); },
fail: async (err) => {
this.productqueryShop(); this.productqueryShop();
} }
}, });
fail: async (err) => { } catch (e) {
console.log(err, '获取错误') //测试用于app this.productqueryShop();
let successres = await this.api.geocodelocation({ //TODO handle the exception
lng: '', }
lat: '',
})
if (successres.code == 0) {
console.log(successres.data.addressComponent.streetNumber.location.split(','))
let res = successres.data.addressComponent.streetNumber.location.split(',')
let datastorage = {
country: successres.data.addressComponent.country, // "中国"
province: successres.data.addressComponent.province, //province: "陕西省"
address: successres.data.addressComponent.city, //district: "西安市"
district: successres.data.addressComponent.district, //district: "未央区"
lng: res[0],
lat: res[1],
}
uni.cache.set('getLocationstorage', datastorage);
this.productqueryShop();
}
}
});
}, },
/** /**
@@ -536,8 +488,10 @@
async productqueryShop() { async productqueryShop() {
let res = await this.api.productqueryShop({ let res = await this.api.productqueryShop({
code: uni.cache.get('tableCode'), code: uni.cache.get('tableCode'),
lng: uni.cache.get('getLocationstorage').lng, lng: uni.cache.get('getLocationstorage').lng ? uni.cache.get('getLocationstorage').lng :
lat: uni.cache.get('getLocationstorage').lat, '',
lat: uni.cache.get('getLocationstorage').lat ? uni.cache.get('getLocationstorage').lat :
'',
}) })
if (res.code == 0) { if (res.code == 0) {
uni.cache.set('shopUser', res.data.storeInfo.id) uni.cache.set('shopUser', res.data.storeInfo.id)
@@ -551,18 +505,18 @@
} }
}, },
/** /**
* 图片加载 * 图片加载
*/ */
imageLoaded (item,index,index1) { imageLoaded(item, index, index1) {
console.log(index) console.log(index)
console.log(index1) console.log(index1)
console.log(this.shopProductList.productInfo[index]) console.log(this.shopProductList.productInfo[index])
this.shopProductList.productInfo[index].products[index1]['imgLoad'] = true; this.shopProductList.productInfo[index].products[index1]['imgLoad'] = true;
// e.currentTarget.src // e.currentTarget.src
}, },
/** /**
* 商品数量增加/减少 * 商品数量增加/减少
* @param {Object} item * @param {Object} item
@@ -757,7 +711,7 @@
start: -1, start: -1,
children: [] children: []
} }
item.value.split(",").forEach((v,e)=>{ item.value.split(",").forEach((v, e) => {
res.children.push({ res.children.push({
name: v, name: v,
isGrounding: false isGrounding: false
@@ -765,7 +719,7 @@
}) })
return res return res
}) })
//初始化第一列规格可编辑 //初始化第一列规格可编辑
let filteredJson; let filteredJson;
let isSkuidname = []; let isSkuidname = [];
@@ -778,14 +732,14 @@
console.log(filteredJson); console.log(filteredJson);
for (let i = 0; i < filteredJson.length; i++) { for (let i = 0; i < filteredJson.length; i++) {
console.log(filteredJson[i].isGrounding) console.log(filteredJson[i].isGrounding)
if ( filteredJson[i].isGrounding ) { if (filteredJson[i].isGrounding) {
this.specifications.tagSnap[0].children[o].isGrounding = true this.specifications.tagSnap[0].children[o].isGrounding = true
break; // 终止循环 break; // 终止循环
} }
} }
} }
this.skuBtnText = `您还没选择${this.specifications.tagSnap[0].name}` this.skuBtnText = `您还没选择${this.specifications.tagSnap[0].name}`
// this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个 // this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个
@@ -809,7 +763,7 @@
* @param {Object} item * @param {Object} item
*/ */
async morloe(e, index, index1, item) { async morloe(e, index, index1, item) {
if ( !e.isGrounding ) { if (!e.isGrounding) {
return; return;
} }
@@ -823,18 +777,18 @@
} }
this.skuidname = []; this.skuidname = [];
this.specifications.tagSnap.forEach((val, i, arr) => { //初始化skuidname的数据 选择第一个 this.specifications.tagSnap.forEach((val, i, arr) => { //初始化skuidname的数据 选择第一个
if ( i > index ) { if (i > index) {
val.children.forEach(( v1,e1)=>{ val.children.forEach((v1, e1) => {
v1.isGrounding = false; v1.isGrounding = false;
}) })
val.start = -1; val.start = -1;
} }
if ( val.start >= 0 ) { if (val.start >= 0) {
this.skuidname.push(val.children[val.start].name) this.skuidname.push(val.children[val.start].name)
} }
}) })
// this.skuidname.splice(index, 1, e.info); //替换skuidname的数据 // this.skuidname.splice(index, 1, e.info); //替换skuidname的数据
for (let i = 0; i < this.specifications.tagSnap.length; i++) { for (let i = 0; i < this.specifications.tagSnap.length; i++) {
if (this.specifications.tagSnap[i].start < 0) { if (this.specifications.tagSnap[i].start < 0) {
this.isSpec = false; this.isSpec = false;
@@ -842,36 +796,36 @@
break; // 终止循环 break; // 终止循环
} }
} }
let filteredJson; let filteredJson;
let isSkuidname = []; let isSkuidname = [];
//提前下一列规格循环,查看是否有下架规格 //提前下一列规格循环,查看是否有下架规格
if ( this.specifications.tagSnap[index+1] ) { if (this.specifications.tagSnap[index + 1]) {
for (let o = 0; o < this.specifications.tagSnap[index+1].children.length; o++) { for (let o = 0; o < this.specifications.tagSnap[index + 1].children.length; o++) {
isSkuidname = JSON.parse(JSON.stringify(this.skuidname)); isSkuidname = JSON.parse(JSON.stringify(this.skuidname));
isSkuidname.push(this.specifications.tagSnap[index+1].children[o].name) isSkuidname.push(this.specifications.tagSnap[index + 1].children[o].name)
//筛选符合条件的规格列表 //筛选符合条件的规格列表
console.log(isSkuidname); console.log(isSkuidname);
filteredJson = this.querySpecList.filter(obj => obj.specSnap.indexOf(isSkuidname) == 0); filteredJson = this.querySpecList.filter(obj => obj.specSnap.indexOf(isSkuidname) == 0);
console.log(filteredJson); console.log(filteredJson);
for (let i = 0; i < filteredJson.length; i++) { for (let i = 0; i < filteredJson.length; i++) {
console.log(filteredJson[i].isGrounding) console.log(filteredJson[i].isGrounding)
if ( filteredJson[i].isGrounding ) { if (filteredJson[i].isGrounding) {
this.specifications.tagSnap[index+1].children[o].isGrounding = true this.specifications.tagSnap[index + 1].children[o].isGrounding = true
break; // 终止循环 break; // 终止循环
} }
} }
} }
} }
// res.data.forEach((v,e)=>{ // res.data.forEach((v,e)=>{
// // this.$set(this.specifications.tagSnap[e], 'children', v.value) // // this.$set(this.specifications.tagSnap[e], 'children', v.value)
// }) // })
console.log(this.specifications.tagSnap) console.log(this.specifications.tagSnap)
this.$forceUpdate(); this.$forceUpdate();
this.hodgepodge(item, 2) this.hodgepodge(item, 2)
}, },

View File

@@ -78,6 +78,7 @@ const store = new Vuex.Store({
uni.cache.set('miniAppOpenId', res.data.userInfo uni.cache.set('miniAppOpenId', res.data.userInfo
.miniAppOpenId) .miniAppOpenId)
uni.cache.set('userInfo', res.data.userInfo); uni.cache.set('userInfo', res.data.userInfo);
this.$isResolve()
} }
}, },
fail: (err) => {} fail: (err) => {}