精简页面初始化代码

This commit is contained in:
zhengw
2026-02-06 15:30:07 +08:00
parent 9ce21008a3
commit f11f4c8000
35 changed files with 85 additions and 376 deletions

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -130,16 +130,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -102,16 +102,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -102,16 +102,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,5 +1,5 @@
import { OSSBaseUrl } from '@/utils/config';
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
formatFileSize,
getAuthInfo,
@@ -76,16 +76,7 @@ Page({
this.data.order_no = order_no;
this.data.head_id = head_id;
this.data.head_id2 = head_id2;
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -118,16 +118,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -128,16 +128,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -128,16 +128,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -128,16 +128,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { menuConfig } from '@/utils/menuConfig';
import { getDataSet, toArray, toObject } from '@/utils/util';
@@ -107,16 +107,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -96,16 +96,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -86,16 +86,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -113,16 +113,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -122,16 +122,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { getAuthInfo, toArray } from '@/utils/util';
Page({
@@ -65,16 +65,7 @@ Page({
this.data.group_id = `${options.group_id}`;
wx.setNavigationBarTitle({ title: `${decodeURIComponent(`${options.name}`)} 权限` });
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { getAuthInfo, toArray } from '@/utils/util';
Page({
@@ -61,16 +61,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(_options) {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -170,16 +170,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,5 +1,5 @@
import { base } from '@/utils/config';
import { checkSesskey, loginStatus, post } from '@/utils/https';
import { checkSesskey, loginStatusPage, post } from '@/utils/https';
import { getStorage, toObject } from '@/utils/util';
Page({
@@ -45,17 +45,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad() {
this.setData({ loading: true });
loginStatus()
.then(() => {
console.log('ssss');
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
loginOut() {
wx.showModal({

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { getAuthInfo, getDataSet, showModal, sleep, toArray, toastSuccess } from '@/utils/util';
Page({
@@ -55,16 +55,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
getAuthInfo,
priceRetentionDigits,
@@ -100,18 +100,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(_options) {
// console.log(options);
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
SaleOrderProcessStateOption,
PayedStateOption,
@@ -184,16 +184,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -124,16 +124,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -96,16 +96,7 @@ Page({
if (title) {
wx.setNavigationBarTitle({ title });
}
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -159,16 +159,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(_options) {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -109,16 +109,7 @@ Page({
if (title) {
wx.setNavigationBarTitle({ title: decodeURIComponent(title) });
}
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -135,16 +135,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -128,16 +128,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { formatTime, getAuthInfo, getDataSet, isArray, toArray, toObject } from '@/utils/util';
import { voiceRequest } from '@/utils/voiceUtil';
@@ -340,15 +340,7 @@ Page({
loading: true,
voice: wx.getStorageSync('processEntryVoice') == 'false' ? false : true,
});
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { SaleOrderProcessStateOption } from '@/utils/config';
import {
cloneLite,
@@ -111,16 +111,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import { getAuthInfo, getDataSet, toArray } from '@/utils/util';
Page({
@@ -44,16 +44,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -113,16 +113,7 @@ Page({
title: decodeURIComponent(options.title || ''),
});
this.data.params.process_id = `${options.process_id || ''}`;
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -123,16 +123,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -125,16 +125,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -128,16 +128,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -1,4 +1,4 @@
import { loginStatus, post } from '@/utils/https';
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
@@ -128,16 +128,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
loginStatusPage(this);
},
/**

View File

@@ -172,6 +172,23 @@ export const loginStatus = () => {
});
};
export const loginStatusPage = (that: WechatMiniprogram.Page.Instance<any, any>) => {
that.setData({ loading: true });
return new Promise<void>((resolve, reject) => {
loginStatus()
.then(() => {
that.setData({ isLogin: true, loading: false });
that?.init?.();
resolve();
})
.catch((err) => {
that.setData({ isLogin: false, loading: false });
reject();
console.log('调用登录状态请求失败', err);
});
});
};
/**
*
* @param {*} config { showLoading: true, showError: true }