添加组件等
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* YangXB 2021.11.24
|
||||
* */
|
||||
import { base, http } from './config';
|
||||
import { Subscribe } from './subscribe';
|
||||
import { IIsLogin, Subscribe } from './subscribe';
|
||||
import { getStorage, isArray, setStorage, toArray, toastError } from './util';
|
||||
/**
|
||||
* 请求
|
||||
@@ -48,7 +48,7 @@ const request = (url: string, options: any, config = { showLoading: true, showEr
|
||||
wx.showToast({ title: request.data.err_msg, icon: 'none' });
|
||||
}
|
||||
if (request.data.err_code == 110000) {
|
||||
Subscribe.set('isLogin', false);
|
||||
Subscribe.set<IIsLogin>('isLogin', false);
|
||||
|
||||
// const currentPage = getCurrentPage();
|
||||
// console.log(currentPage);
|
||||
@@ -147,7 +147,7 @@ export const loginStatus = () => {
|
||||
setStorage('auth_info', res.auth_info);
|
||||
setStorage('session_id', res.session_id);
|
||||
getUsersConfigList();
|
||||
Subscribe.set('isLogin', true);
|
||||
Subscribe.set<IIsLogin>('isLogin', true);
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err: any) => {
|
||||
@@ -157,7 +157,7 @@ export const loginStatus = () => {
|
||||
post('Applet/loginOut').then(() => {
|
||||
checkSesskey({ showLoading: false, showError: false })
|
||||
.then(() => {
|
||||
Subscribe.set('isLogin', false);
|
||||
Subscribe.set<IIsLogin>('isLogin', false);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('checkSesskey', err);
|
||||
@@ -204,7 +204,7 @@ export const onPageLoadInitAuth = (
|
||||
initFun()
|
||||
.then((_res) => {
|
||||
// console.log('onPageLoadInitAuth', res);
|
||||
Subscribe.set('isLogin', true);
|
||||
Subscribe.set<IIsLogin>('isLogin', true);
|
||||
that.setData({ isLogin: true, loading: false });
|
||||
that.init?.();
|
||||
})
|
||||
|
||||
@@ -18,13 +18,18 @@ function triggerEvent(key: string, data: any) {
|
||||
|
||||
type IFun = Function & { $$functionKey?: string };
|
||||
|
||||
/**
|
||||
* isLogin 的数据类型
|
||||
*/
|
||||
export type IIsLogin = boolean;
|
||||
|
||||
export const Subscribe = {
|
||||
/**
|
||||
* 设置
|
||||
* @param key 订阅变量的key
|
||||
* @param value 值
|
||||
*/
|
||||
set(key: string, value: any) {
|
||||
set<T>(key: string, value: T) {
|
||||
// 1. 执行原有的存储操作
|
||||
// setStorage(key, value);
|
||||
// 2. 触发自定义事件,通知订阅者
|
||||
@@ -35,6 +40,10 @@ export const Subscribe = {
|
||||
// return getStorage(key);
|
||||
// },
|
||||
|
||||
/**
|
||||
* 批量移除订阅
|
||||
* @param key 订阅变量的key
|
||||
*/
|
||||
remove(key: string) {
|
||||
triggerEvent(key, null); // 或者触发一个 'remove' 事件
|
||||
},
|
||||
@@ -45,7 +54,7 @@ export const Subscribe = {
|
||||
* @param functionKey 唯一的函数key(用于取消订阅的)
|
||||
* @param callback 回调函数
|
||||
*/
|
||||
on(key: string, functionKey: string, callback: (data: any) => void) {
|
||||
on<T>(key: string, functionKey: string, callback: (data: T) => void) {
|
||||
if (!listeners[key]) {
|
||||
listeners[key] = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user