Browse Source

登录完成后跳转回触发登录的页面

master
kola-web 2 months ago
parent
commit
66552cc272
  1. 2
      project.config.json
  2. 18
      src/app.ts
  3. 2
      src/pages/article/index.scss
  4. 11
      src/pages/article/index.ts
  5. 2
      src/pages/article/index.wxml
  6. 7
      src/pages/classify/index.ts
  7. 4
      src/pages/home/index.scss
  8. 5
      src/pages/login/index.ts
  9. 7
      src/pages/search/index.ts
  10. 9
      src/pages/search/index.wxml
  11. 3
      typings/index.d.ts

2
project.config.json

@ -61,5 +61,5 @@
} }
] ]
}, },
"appid": "wxa4a28b299df7d921" "appid": "wxbdf6f933281b1eb4"
} }

18
src/app.ts

@ -17,20 +17,22 @@ App<IAppOption>({
// 测试号 wx2b0bb13edf717c1d // 测试号 wx2b0bb13edf717c1d
// dev // dev
// appid:wxbdf6f933281b1eb4 // appid:wxbdf6f933281b1eb4
// url: 'https://m.shizhong.hbraas.com', url: 'https://m.shizhong.hbraas.com',
// upFileUrl: 'https://m.shizhong.hbraas.com/', upFileUrl: 'https://m.shizhong.hbraas.com/',
// imageUrl: 'https://m.shizhong.hbraas.com/api/shizhong/', imageUrl: 'https://m.shizhong.hbraas.com/api/shizhong/',
// pro // pro
// appid:wxa4a28b299df7d921 // appid:wxa4a28b299df7d921
url: 'https://m.shizhong.hbsaas.com', // url: 'https://m.shizhong.hbsaas.com',
upFileUrl: 'https://m.shizhong.hbsaas.com/', // upFileUrl: 'https://m.shizhong.hbsaas.com/',
imageUrl: 'https://m.shizhong.hbsaas.com/api/shizhong/', // imageUrl: 'https://m.shizhong.hbsaas.com/api/shizhong/',
loginState: '', loginState: '',
isLogin: 0, isLogin: 0,
isAnswer: '0', isAnswer: '0',
scene: null, scene: null,
backPath: '',
}, },
onLaunch() { onLaunch() {
Page = page as WechatMiniprogram.Page.Constructor; Page = page as WechatMiniprogram.Page.Constructor;
@ -63,7 +65,7 @@ App<IAppOption>({
this.globalData.scene = parseScene(options.query.scene); this.globalData.scene = parseScene(options.query.scene);
} }
}, },
waitLogin(waitLoginState = false, requireLogin = false) { waitLogin(waitLoginState = false, requireLogin = false, bakcPath = '') {
let time: number; let time: number;
return new Promise((resolve) => { return new Promise((resolve) => {
time = setInterval(() => { time = setInterval(() => {
@ -73,8 +75,10 @@ App<IAppOption>({
if (waitLoginState) { if (waitLoginState) {
resolve(true); resolve(true);
} else if (isLogin === 0 || !isLogin) { } else if (isLogin === 0 || !isLogin) {
this.globalData.backPath = bakcPath;
wx.reLaunch({ url: '/pages/login/index' }); wx.reLaunch({ url: '/pages/login/index' });
} else if (requireLogin && isLogin === 999) { } else if (requireLogin && isLogin === 999) {
this.globalData.backPath = bakcPath;
wx.reLaunch({ url: '/pages/login/index' }); wx.reLaunch({ url: '/pages/login/index' });
} else { } else {
resolve(true); resolve(true);

2
src/pages/article/index.scss

@ -1,5 +1,5 @@
.page { .page {
padding: 48rpx 32rpx 200rpx; padding: 48rpx 20rpx 200rpx;
.page-title { .page-title {
font-size: 44rpx; font-size: 44rpx;

11
src/pages/article/index.ts

@ -246,9 +246,18 @@ Page({
this.setData({ this.setData({
toastShow: false, toastShow: false,
}); });
wx.navigateBack(); wx.navigateBack({
fail() {
wx.reLaunch({
url: '/pages/classify/index',
});
},
});
}, },
handleAuthConform() { handleAuthConform() {
const { BookId, ChapterId } = this.data;
const backPath = `/pages/article/index?id=${BookId}&cid=${ChapterId}`;
app.globalData.backPath = backPath;
wx.navigateTo({ wx.navigateTo({
url: '/pages/login/index?back=1', url: '/pages/login/index?back=1',
}); });

2
src/pages/article/index.wxml

@ -39,7 +39,7 @@
</van-slider> </van-slider>
</view> </view>
<view class="rich"> <view class="rich">
<mp-html content="{{chapter.Content}}" scroll-table="{{true}}"></mp-html> <mp-html content="{{chapter.Content}}" scroll-table="{{true}}" show-img-menu="{{false}}"></mp-html>
</view> </view>
<view <view
class="quick-article" class="quick-article"

7
src/pages/classify/index.ts

@ -26,7 +26,7 @@ Page({
}, },
onLoad(options) { onLoad(options) {
this.setData({ this.setData({
CateId: options.id, CateId: options.id || '',
}); });
app.waitLogin().then(() => { app.waitLogin().then(() => {
this.getCateList(); this.getCateList();
@ -185,9 +185,10 @@ Page({
}, },
handleDetail(e) { handleDetail(e) {
const { id } = e.currentTarget.dataset; const { id } = e.currentTarget.dataset;
app.waitLogin(false, true).then(() => { const backPath = `/pages/article/index?id=${id}`;
app.waitLogin(false, true, backPath).then(() => {
wx.navigateTo({ wx.navigateTo({
url: `/pages/article/index?id=${id}`, url: backPath,
}); });
}); });
}, },

4
src/pages/home/index.scss

@ -43,7 +43,7 @@ page {
} }
} }
.swiper { .swiper {
margin: 36rpx 32rpx 0; margin: 36rpx 32rpx -52rpx;
height: 318rpx; height: 318rpx;
.wx-swiper-dots { .wx-swiper-dots {
@ -89,7 +89,7 @@ page {
} }
.cards { .cards {
margin: 0 32rpx; margin: 52rpx 32rpx 0;
display: grid; display: grid;
gap: 28rpx 26rpx; gap: 28rpx 26rpx;
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);

5
src/pages/login/index.ts

@ -136,7 +136,9 @@ Page({
}, },
submitCallback() { submitCallback() {
app.globalData.isLogin = 1; app.globalData.isLogin = 1;
wx.reLaunch({ url: '/pages/home/index' }); const backPath = app.globalData.backPath;
wx.reLaunch({ url: backPath || '/pages/home/index' });
app.globalData.backPath = '';
}, },
handleProtool() { handleProtool() {
this.setData({ this.setData({
@ -149,6 +151,7 @@ Page({
handleVisitor() { handleVisitor() {
if (app.globalData.isLogin !== 1) { if (app.globalData.isLogin !== 1) {
app.globalData.isLogin = 999; app.globalData.isLogin = 999;
app.globalData.backPath = '';
} }
wx.reLaunch({ wx.reLaunch({
url: '/pages/home/index', url: '/pages/home/index',

7
src/pages/search/index.ts

@ -65,10 +65,11 @@ Page({
wx.navigateBack(); wx.navigateBack();
}, },
handleDetail(e) { handleDetail(e) {
const { id } = e.currentTarget.dataset; const { id, cid } = e.currentTarget.dataset;
app.waitLogin(false, true).then(() => { const backPath = `/pages/article/index?id=${id}&cid=${cid}`;
app.waitLogin(false, true, backPath).then(() => {
wx.navigateTo({ wx.navigateTo({
url: `/pages/article/index?id=${id}`, url: backPath,
}); });
}); });
}, },

9
src/pages/search/index.wxml

@ -23,7 +23,14 @@
/> />
</view> </view>
<view class="tip" wx:if="{{list.length}}">以下为搜到的内容</view> <view class="tip" wx:if="{{list.length}}">以下为搜到的内容</view>
<view class="card" wx:for="{{list}}" wx:key="index" bind:tap="handleDetail" data-id="{{item.BookId}}"> <view
class="card"
wx:for="{{list}}"
wx:key="index"
bind:tap="handleDetail"
data-id="{{item.BookId}}"
data-cid="{{item.ChapterId}}"
>
<image class="photo" mode="aspectFill" src="{{item.CoverUrl}}"></image> <image class="photo" mode="aspectFill" src="{{item.CoverUrl}}"></image>
<view class="c-container"> <view class="c-container">
<view class="title">{{item.ChapterName}}</view> <view class="title">{{item.ChapterName}}</view>

3
typings/index.d.ts vendored

@ -8,9 +8,10 @@ interface IAppOption {
isLogin: 0 | 1 | 999; isLogin: 0 | 1 | 999;
isAnswer: '0' | '1'; isAnswer: '0' | '1';
scene: null | { [key: string]: any }; scene: null | { [key: string]: any };
backPath: string;
}; };
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback; userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback;
waitLogin: (waitLoginState?: boolean, requireLogin?: boolean) => Promise<any>; waitLogin: (waitLoginState?: boolean, requireLogin?: boolean, backPath?: string) => Promise<any>;
getMenuInfo: (arg0: WechatMiniprogram.Page.Instance<any, any>) => void; getMenuInfo: (arg0: WechatMiniprogram.Page.Instance<any, any>) => void;
getUserInfo: (arg0: WechatMiniprogram.Page.Instance<any, any>, arg1?: (arg0: any) => void) => void; getUserInfo: (arg0: WechatMiniprogram.Page.Instance<any, any>, arg1?: (arg0: any) => void) => void;
} }

Loading…
Cancel
Save