Commit b80d34f1 by liimin

refactor(tab): 优化个人中心页面结构和代码

- 移除了 ChannelsModal 组件
- 重构了 myOrder 组件,优化了订单列表的展示
- 优化了个人中心页面的布局和样式
- 调整了网络状态监听器的实现
1 parent 36ac356c
### 注意:
1. 此文件夹只分:
1.1. mall.js (商城模块)
1.2. cart.js (购物车模块)
1.3. mine.js (我的模块)
1.4. common.js (除以上三大模块之外的所有接口统一放在此文件)
1.5. index.js (首页模块 对外统一导出)
2. 后续如果有模块新增再调整
\ No newline at end of file
export * from "./mine";
export const ToolList = Object.freeze([
{
text: '我的地址',
icon: 'myAddress',
url: '/packageMine/pages/address/index/index'
}
]);
// pages/tab/index/components/ChannelsModal/ChannelsModal.js
import {
systemApi
} from '~/api/index'
import {
IMG_URL
} from '~/config'
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
showChannels: true
},
/**
* 组件的方法列表
*/
methods: {
noScroll() {},
async init(auto = true) {
const {
finderUserName
} = await wx.p.api.systemApi.getMockData()
this.setData({
finderUserName: finderUserName || 'sph7YsAMEGQixoU'
})
this.getChannelsLiveInfo(auto)
},
getChannelsLiveInfo(auto) {
const _this = this,
{
finderUserName
} = this.data
wx.getChannelsLiveInfo({
finderUserName,
success(liveInfo) {
console.log('视频号直播信息:', liveInfo)
if (liveInfo.status == 3) {
_this.getChannelsLiveNoticeInfo(finderUserName, auto)
liveInfo = null
} else if (!auto) _this.close()
_this.setData({
liveInfo
})
},
fail(err) {
console.log(err)
_this.getChannelsLiveNoticeInfo(finderUserName, auto)
}
})
},
getChannelsLiveNoticeInfo(finderUserName, auto) {
const _this = this
wx.getChannelsLiveNoticeInfo({
finderUserName,
success(liveNoticeInfo) {
console.log('视频号预告信息:', liveNoticeInfo)
let startTime = liveNoticeInfo.startTime * 1e3,
month = new Date(startTime).format('M'),
day = new Date(startTime).format('d'),
time = new Date(startTime).format('hh:mm')
liveNoticeInfo = {
...liveNoticeInfo,
month,
day,
time
}
_this.setData({
liveNoticeInfo
})
if (!auto) _this.close()
},
fail(err) {
console.log('视频号预告信息:', err)
_this.setData({
liveNoticeInfo: null
})
}
})
},
jumpLive() {
const {
liveInfo: {
feedId,
nonceId
},
finderUserName
} = this.data,
_this = this
wx.openChannelsLive({
finderUserName,
feedId,
nonceId,
success(res) {
_this.close()
},
fail(err) {
if (err && err.errMsg && !err.errMsg.includes('cancel')) wx.p.wxApi.showToast(err.errMsg)
}
})
},
reserve() {
this.close()
const {
noticeId
} = this.data.liveNoticeInfo
wx.reserveChannelsLive({
noticeId
})
},
close(e) {
if (e) this.setData({
animation: true
}, setTimeout(() => {
this.setBanner()
}, .3e3))
else this.setBanner()
},
async setBanner() {
const v = await systemApi.getImageVersion() || Date.now()
const {
liveInfo,
liveNoticeInfo,
finderUserName
} = this.data,
bannerImg = `${IMG_URL}home/live/${liveInfo ? 'live' :'notice'}.png?v=${v}`,
thisPage = wx.p.router.getPageInstance()
let {
bannerList
} = thisPage.data,
item = liveInfo || liveNoticeInfo,
obj = {
bannerImg,
bannerType: 'channels',
type: liveInfo ? 1 : 0,
finderUserName,
...item,
}
if (!bannerList) bannerList = []
bannerList.unshift(obj)
thisPage.setData({
bannerList
})
this.setData({
showChannels: false
})
}
},
lifetimes: {
ready() {
this.init()
}
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
/* pages/tab/index/components/ChannelsModal/ChannelsModal.wxss */
.channels {
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
z-index: 101;
&-bg {
width: 100%;
height: 100%;
background-color: rgba($color: #000000, $alpha: .5);
}
&-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 590rpx;
background: #8A303A;
border-radius: 16rpx;
animation: show-live-box .5s forwards;
.close {
position: absolute;
top: 20rpx;
right: 20rpx;
width: 36rpx;
height: 36rpx;
z-index: 3;
}
.live-box {
width: 100%;
min-height: 994rpx;
.live-view {
height: 800rpx;
}
.live-info {
font-weight: 500;
font-size: 24rpx;
color: #FFFFFF;
text-align: center;
padding: 20rpx 55rpx 48rpx;
.text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.channels-btn {
margin: 20rpx auto 0;
}
}
}
.notice-bg {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.notice-box {
min-height: 892rpx;
position: relative;
z-index: 1;
.notice-title {
font-weight: 600;
font-size: 28rpx;
color: #FFFFFF;
letter-spacing: 2rpx;
padding: 24rpx 0;
text-align: center;
}
.notice-head-url {
width: 486rpx;
height: 480rpx;
position: absolute;
top: 112rpx;
left: 50%;
transform: translateX(-50%);
border-radius: 16rpx;
overflow: hidden;
}
.notice-time {
position: absolute;
left: 50%;
bottom: 208rpx;
transform: translateX(-50%);
width: 100%;
font-size: 60rpx;
color: #8A303A;
display: flex;
justify-content: center;
align-items: baseline;
line-height: 72rpx;
.unit {
font-size: 28rpx;
margin: 0 10rpx;
line-height: 40rpx;
}
}
.channels-btn {
position: absolute;
left: 50%;
bottom: 48rpx;
transform: translateX(-50%);
}
}
.channels-btn {
width: 264rpx;
height: 72rpx;
background-image: radial-gradient(circle at 12% 25%, #FFEDC9 0%, #E7AE6E 98%);
border-radius: 12rpx;
font-weight: 600;
font-size: 28rpx;
color: #000000;
letter-spacing: 2rpx;
display: flex;
align-items: center;
justify-content: center;
}
}
}
.true {
animation: close-live-box .5s forwards;
overflow: hidden;
}
@keyframes close-live-box {
0% {
opacity: 1;
}
100% {
height: 140rpx;
opacity: 0;
top: 35%;
left: 0;
}
}
@keyframes show-live-box {
0% {
opacity: 0;
transform: translate(-50%, -50%) scale(.15);
}
100% {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
}
\ No newline at end of file
<block wx:if="{{(liveInfo || liveNoticeInfo) && showChannels}}">
<view class="channels {{animation}}" catchtouchmove="noScroll">
<view class="channels-bg"></view>
<view class="channels-box">
<view class="close" bindtap="close">
<glsx-image src="home/live/close.png" />
</view>
<block wx:if="{{liveInfo}}">
<view class="live-box">
<view class="live-view" bindtap="close">
<channel-live feed-id="{{liveInfo.feedId}}" finder-user-name="{{finderUserName}}"></channel-live>
</view>
<view class="live-info">
<view class="text">{{liveInfo.description}}</view>
<view class="channels-btn" bindtap="jumpLive">进入直播间</view>
</view>
</view>
</block>
<block wx:else>
<view class="notice-bg">
<glsx-image src="home/live/notice-bg.png"></glsx-image>
</view>
<view class="notice-box">
<view class="notice-title">
视频号直播预告
</view>
<view class="notice-head-url">
<image src="{{liveNoticeInfo.headUrl}}" />
</view>
<view class="notice-time">
{{liveNoticeInfo.month}}
<view class="unit">月</view>
{{liveNoticeInfo.day}}
<view class="unit day">日</view>
{{liveNoticeInfo.time}}
</view>
<view class="channels-btn" bindtap="reserve">立即预约</view>
</view>
</block>
</view>
</view>
</block>
\ No newline at end of file
......@@ -6,8 +6,7 @@
"good-tab": "./components/good-tab/good-tab",
"goods": "./components/goods/goods",
"activity": "./components/activity/activity",
"customer": "./components/customer/customer",
"channels-modal": "./components/ChannelsModal/ChannelsModal"
"customer": "./components/customer/customer"
},
"navigationStyle": "custom",
"onReachBottomDistance": 10,
......
......@@ -4,34 +4,31 @@ Component({
* 组件的属性列表
*/
properties: {
orderNumberList: Object
orderNumberList: Object,
},
/**
* 组件的初始数据
*/
data: {
orderList: [{
text: '待支付',
imageUrl: 'noPay'
orderList: Object.freeze([
{
text: "待支付",
imageUrl: "noPay",
},
{
text: '待发货',
imageUrl: 'noTakeCommodity'
text: "待发货",
imageUrl: "noTakeCommodity",
},
{
text: '待收货',
imageUrl: 'takeCommodity'
text: "待收货",
imageUrl: "takeCommodity",
},
// {
// text: '评价',
// imageUrl: 'appraise'
// },
{
text: '售后',
imageUrl: 'aftermarket'
}
]
text: "售后",
imageUrl: "aftermarket",
},
]),
},
/**
......@@ -39,13 +36,11 @@ Component({
*/
methods: {
goOrder(e) {
let {
key
} = e.currentTarget.dataset,
tabIndex = key || 0
wx.p.router.go('/packageMine/pages/order/index/index', {
tabIndex
})
}
}
})
\ No newline at end of file
let { key } = e.currentTarget.dataset,
tabIndex = key || 0;
wx.p.router.go("/packageMine/pages/order/index/index", {
tabIndex,
});
},
},
});
// pages/tab/mine/index.js
import { ToolList } from "~/constants/index";
Page({
/**
* 页面的初始数据
*/
data: {
toolList: [{
text: '购物车',
icon: 'myShopping',
url: '/packageMall/pages/shoppingCart/shoppingCart'
},
{
text: '我的地址',
icon: 'myAddress',
url: '/packageMine/pages/address/index/index'
},
],
vipType: {
1: 'gold_vip_bg',
2: 'silver_vip_bg',
3: 'pt_vip_bg'
},
titleClass: {
1: 'gold_title',
2: 'sliver_title',
3: 'card_title',
},
dateClass: {
1: 'gold_date',
2: 'sliver_date',
3: 'card_date',
}
toolList: ToolList,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getMemberCardData()
// this.getMemberCardData();
},
navbarReady(e) {
let {
height
} = e.detail
let { height } = e.detail;
this.setData({
user_box_style: `padding-top:${height + 20}px`
})
user_box_style: `padding-top:${height + 20}px`,
});
},
login() {
wx.p.router.go('/pages/Login/Login')
wx.p.router.go("/pages/Login/Login");
},
goSetUp() {
wx.p.router.go('/packageMine/pages/setting/index')
wx.p.router.go("/packageMine/pages/setting/index");
},
jump(e) {
const {
url
} = e.currentTarget.dataset
wx.p.router.go(url)
const { url } = e.currentTarget.dataset;
wx.p.router.go(url);
},
async getOrderNumberList() {
const loginStatus = await wx.p.router.intercept(false)
if (loginStatus) return
wx.p.api.mineApi.getOrderNumberList().then(res => {
const loginStatus = await wx.p.router.intercept(false);
if (loginStatus) return;
wx.p.api.mineApi.getOrderNumberList().then((res) => {
this.setData({
orderNumberList: [res.unPayCount, res.unShippedCount, res.unReceivedCount, res.unServiceCount]
})
})
orderNumberList: [
res.unPayCount,
res.unShippedCount,
res.unReceivedCount,
res.unServiceCount,
],
});
});
},
// 获取用户会员信息
toCheckMember() {
wx.p.router.intercept(false).then(sid => {
wx.p.router.intercept(false).then((sid) => {
if (sid) {
this.setData({
isMember: false,
memberFlag: true
})
memberFlag: true,
});
} else {
wx.p.api.equityApi.checkOpenMember().then(res => {
wx.p.api.equityApi.checkOpenMember().then((res) => {
let flag = false,
identity = 0 // 普通会员3 银卡2 金卡1 非会员 0
identity = 0; // 普通会员3 银卡2 金卡1 非会员 0
if (res.data && res.data.validitDate) {
res.data.time = new Date(res.data.validitDate).format('yyyy.MM.dd')
res.data.time = new Date(res.data.validitDate).format("yyyy.MM.dd");
}
if (res.data && res.data.endTime) {
res.data.endTime = new Date(res.data.endTime).format('yyyy.MM.dd')
res.data.endTime = new Date(res.data.endTime).format("yyyy.MM.dd");
}
if (res.code == 0 && res.data) {
flag = true
identity = 3
if (res.data && res.data.cardTypeSpecial) identity = res.data.cardTypeSpecial
flag = true;
identity = 3;
if (res.data && res.data.cardTypeSpecial)
identity = res.data.cardTypeSpecial;
}
wx.p.storage.set('isVIP', flag)
wx.p.storage.set("isVIP", flag);
this.setData({
isMember: flag,
vipInfo: res.data,
identity,
memberFlag: true
})
})
memberFlag: true,
});
});
}
})
},
// 获取门店会员卡信息
getMemberCardData() {
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
wx.p.api.equityApi.memberCard(para).then(res => {
this.setData({
memberInfo: res
})
})
},
goInterests() {
wx.p.router.switchTab('/pages/tab/equity/index')
},
// 开通会员页面
toBuyMember() {
wx.p.router.go('/packageEquity/pages/open/open',{
notIntercept: true
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.getOrderNumberList()
this.toCheckMember()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.getOrderNumberList();
this.toCheckMember();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ No newline at end of file
});
......@@ -27,56 +27,6 @@ page {
font-weight: 500;
font-size: 32rpx;
}
.gold_title {
background: linear-gradient(125deg, #645E54 100%, #29271E 100%) !important;
-webkit-background-clip: text !important;
background-clip: text !important;
color: transparent !important;
font-weight: 600;
font-size: 32rpx;
}
.card_title {
background: linear-gradient(125deg, #F0EED7 100%, #F2EAAB 100%) !important;
-webkit-background-clip: text !important;
background-clip: text !important;
color: transparent !important;
}
.sliver_title {
background: linear-gradient(125deg, #C99113 100%, #A9790B 100%) !important;
-webkit-background-clip: text !important;
background-clip: text !important;
color: transparent !important;
}
.card_date {
position: absolute;
left: 40rpx;
bottom: 40rpx;
background: linear-gradient(125deg, #F0EED7 100%, #F2EAAB 100%) !important;
-webkit-background-clip: text !important;
background-clip: text !important;
color: transparent !important;
font-weight: 400;
font-size: 20rpx;
}
.sliver_date {
background: linear-gradient(125deg, #C99113 100%, #A9790B 100%) !important;
-webkit-background-clip: text !important;
background-clip: text !important;
color: transparent !important;
}
.gold_date {
background: linear-gradient(125deg, #645E54 100%, #29271E 100%) !important;
-webkit-background-clip: text !important;
background-clip: text !important;
color: transparent !important;
}
}
.navigation-bar {
......
......@@ -58,26 +58,9 @@
<view class="vip-box-bg">
<glsx-image src="equity/version/1_0_0/{{vipType[identity]}}.png"></glsx-image>
</view>
<view class="vip-name {{titleClass[identity]}}">{{identity==1?vipInfo.goldName:identity==2?vipInfo.silverName:memberInfo.equityName}}</view>
<view wx:if="{{vipInfo.cardNo&&identity==3}}" class="card_date {{dateClass[identity]}}">{{vipInfo.time}} 到期</view>
<view wx:elif="{{vipInfo.cardNo&&identity<3}}" class="card_date {{dateClass[identity]}}">{{vipInfo.endTime}} 到期</view>
<view wx:elif="{{!vipInfo.cardNo}}" class="card_date {{dateClass[identity]}}"> {{vipInfo.renewDay}}天后到期</view>
</view>
<!-- <view class="goUseBox" bindtap="goInterests">
去使用
<view class="goUseBox-icon">
<glsx-image webp src="mine/goUse.png"></glsx-image>
</view>
</view> -->
</block>
</block>
<!-- 我的券包 -->
<view class="coupon-box box flex" bindtap="jump" data-url="/packageMine/pages/coupon/index/index">
我的卡券
<view class="icon">
<glsx-image src="mine/mine-arrow.png"></glsx-image>
</view>
</view>
<!-- 我的订单 -->
<myOrder orderNumberList="{{orderNumberList}}" />
<!-- 常用工具 -->
......
const ISCOMMECTED = Symbol('ISCOMMECTED')
const ISCOMMECTED = Symbol("ISCOMMECTED");
class NetWork {
[ISCOMMECTED] = false;
constructor() {
this.onNetworkStatusChange()
this.onNetworkStatusChange();
}
/**监听网络变化 */
onNetworkStatusChange() {
wx.onNetworkStatusChange(({
isConnected,
networkType
}) => {
wx.onNetworkStatusChange(({ isConnected, networkType }) => {
if (!isConnected && !this[ISCOMMECTED]) {
this[ISCOMMECTED] = true
this[ISCOMMECTED] = true;
wx.showToast({
icon: 'loading',
title: '网络尚未连接',
icon: "loading",
title: "网络尚未连接",
mask: true,
duration: 36e3 * 24
})
duration: 36e3 * 24,
});
} else {
if (this[ISCOMMECTED]) {
const thisPage = wx.p.router.getPageInstance(),
options = Object.keys(thisPage.options)
this[ISCOMMECTED] = false
wx.showLoading()
wx.hideLoading()
options = Object.keys(thisPage.options);
this[ISCOMMECTED] = false;
wx.showLoading();
wx.hideLoading();
// if (thisPage.noPageAuth) {
// wx.showLoading()
// this.refreshPage()
......@@ -44,48 +41,42 @@ class NetWork {
// }
}
}
})
});
}
getNetworkType() {
const that = this
const that = this;
return new Promise((resolve, reject) => {
wx.getNetworkType({
success({
networkType
}) {
that[ISCOMMECTED] = networkType == 'none'
resolve(networkType)
success({ networkType }) {
that[ISCOMMECTED] = networkType == "none";
resolve(networkType);
},
fail: err => reject(err)
})
})
fail: (err) => reject(err),
});
});
}
netWorkModal(confirmText = '返回') {
netWorkModal(confirmText = "返回") {
return new Promise((resolve, reject) => {
wx.showModal({
content: '网络尚未连接,请稍后再试',
content: "网络尚未连接,请稍后再试",
confirmText,
showCancel: false,
confirmColor: '#3666FE',
confirmColor: "#3666FE",
success(res) {
if (res.confirm) resolve()
if (res.cancel) reject()
}
})
})
if (res.confirm) resolve();
if (res.cancel) reject();
},
});
});
}
/**页面重载 */
refreshPage() {
wx.hideLoading()
wx.showNavigationBarLoading()
wx.hideLoading();
wx.showNavigationBarLoading();
const thisPage = wx.p.router.getPageInstance(),
{
onLoad,
onShow,
options
} = thisPage
if (onLoad) thisPage.onLoad(options, true)
if (onShow) thisPage.onShow(options, true)
{ onLoad, onShow, options } = thisPage;
if (onLoad) thisPage.onLoad(options, true);
if (onShow) thisPage.onShow(options, true);
}
}
export default new NetWork()
\ No newline at end of file
export default new NetWork();
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!