@fairys/taro-tools-react 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,6 +65,14 @@ export declare class AuthDataInstance<T = any> {
65
65
  * @returns 是否有指定权限
66
66
  */
67
67
  hasPermission(permission: string): boolean;
68
+ /**
69
+ * 清除登录凭证(token)、权限列表、菜单权限列表、用户信息
70
+ */
71
+ clear(): void;
72
+ /**
73
+ * 初始化认证数据实例
74
+ */
75
+ constructor();
68
76
  }
69
77
  export declare const authDataInstance: AuthDataInstance<any>;
70
78
  /**
@@ -76,6 +76,22 @@ class AuthDataInstance {
76
76
  if (!globalSettingDataInstance.store.isEnableAuth) return true;
77
77
  return this.permissions.includes(permission);
78
78
  }
79
+ clear() {
80
+ this.token = '';
81
+ this.permissions = [];
82
+ this.menusPermissions = [];
83
+ this.userInfo = void 0;
84
+ }
85
+ constructor(){
86
+ try {
87
+ this.store.userInfo = this.userInfo;
88
+ this.store.token = this.token;
89
+ this.store.permissions = this.permissions;
90
+ this.store.menusPermissions = this.menusPermissions;
91
+ } catch (error) {
92
+ console.error("\u521D\u59CB\u5316\u8BA4\u8BC1\u6570\u636E\u5B9E\u4F8B\u5931\u8D25", error);
93
+ }
94
+ }
79
95
  }
80
96
  const authDataInstance = new AuthDataInstance();
81
97
  function useAuthData() {
@@ -1,4 +1,5 @@
1
1
  export * from './global.data.instance';
2
2
  export * from './page.data.instance';
3
3
  export * from './page.info.data.instance';
4
+ export * from './auth.data.instance';
4
5
  export * from './global.setting.data.instance';
@@ -1,4 +1,5 @@
1
1
  export * from "./global.data.instance.js";
2
2
  export * from "./page.data.instance.js";
3
3
  export * from "./page.info.data.instance.js";
4
+ export * from "./auth.data.instance.js";
4
5
  export * from "./global.setting.data.instance.js";
@@ -97,7 +97,7 @@ export declare class PageDataInstance<T extends PageDataInstanceState = PageData
97
97
  /**内置——查询方法*/
98
98
  main_onSearch: () => void;
99
99
  /**加载更多*/
100
- main_onLoadMore: () => void;
100
+ main_onLoadMore: () => Promise<void>;
101
101
  }
102
102
  export interface PageDataOptions<T extends PageDataInstanceState = PageDataInstanceState> {
103
103
  /**初始值*/
@@ -210,7 +210,7 @@ class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
210
210
  this.main_onPageChange(1);
211
211
  this.store.expandSearch = false;
212
212
  };
213
- main_onLoadMore = ()=>{
213
+ main_onLoadMore = async ()=>{
214
214
  if (this.store.loading?.pageLoading) return;
215
215
  const isTabs = this.store.isTabs;
216
216
  if (isTabs) {
@@ -233,10 +233,12 @@ class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
233
233
  [`${tabKey}LoadMore`]: true
234
234
  });
235
235
  this._setValues({
236
- [`${tabKey}Page`]: nextPage,
236
+ [`${tabKey}Page`]: nextPage
237
+ });
238
+ await this.main_getList();
239
+ this._setValues({
237
240
  [`${tabKey}HasLastPage`]: hasLastPage
238
241
  });
239
- this.main_getList();
240
242
  return;
241
243
  }
242
244
  const total = this.store.total || 0;
@@ -255,10 +257,12 @@ class page_data_instance_PageDataInstance extends ProxyInstanceObjectBase {
255
257
  if (nextPage >= count && total) hasLastPage = true;
256
258
  this.store.loading.loadMore = true;
257
259
  this._setValues({
258
- page: nextPage,
260
+ page: nextPage
261
+ });
262
+ await this.main_getList();
263
+ this._setValues({
259
264
  hasLastPage
260
265
  });
261
- this.main_getList();
262
266
  };
263
267
  }
264
268
  function usePageDataInstance(instance) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "SunLxy <1011771396@qq.com>",
4
4
  "description": "框架组件库",
5
5
  "homepage": "https://github.com/autumn-fairy-tales/fairys-taro-react",
6
- "version": "1.0.2",
6
+ "version": "1.0.4",
7
7
  "main": "lib/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "module": "esm/index.js",
@@ -162,6 +162,30 @@ export class AuthDataInstance<T = any> {
162
162
  }
163
163
  return this.permissions.includes(permission);
164
164
  }
165
+
166
+ /**
167
+ * 清除登录凭证(token)、权限列表、菜单权限列表、用户信息
168
+ */
169
+ clear() {
170
+ this.token = '';
171
+ this.permissions = [];
172
+ this.menusPermissions = [];
173
+ this.userInfo = undefined;
174
+ }
175
+
176
+ /**
177
+ * 初始化认证数据实例
178
+ */
179
+ constructor() {
180
+ try {
181
+ this.store.userInfo = this.userInfo;
182
+ this.store.token = this.token;
183
+ this.store.permissions = this.permissions;
184
+ this.store.menusPermissions = this.menusPermissions;
185
+ } catch (error) {
186
+ console.error('初始化认证数据实例失败', error);
187
+ }
188
+ }
165
189
  }
166
190
 
167
191
  export const authDataInstance = new AuthDataInstance();
@@ -1,4 +1,5 @@
1
1
  export * from './global.data.instance';
2
2
  export * from './page.data.instance';
3
3
  export * from './page.info.data.instance';
4
+ export * from './auth.data.instance';
4
5
  export * from './global.setting.data.instance';
@@ -301,7 +301,7 @@ export class PageDataInstance<
301
301
  this.store.expandSearch = false;
302
302
  };
303
303
  /**加载更多*/
304
- main_onLoadMore = () => {
304
+ main_onLoadMore = async () => {
305
305
  if (this.store.loading?.pageLoading) {
306
306
  // 加载中,不进行请求
307
307
  return;
@@ -329,9 +329,9 @@ export class PageDataInstance<
329
329
  // 判断是否最后一页数据
330
330
  this._setValues({
331
331
  [`${tabKey}Page`]: nextPage,
332
- [`${tabKey}HasLastPage`]: hasLastPage,
333
332
  });
334
- this.main_getList();
333
+ await this.main_getList();
334
+ this._setValues({ [`${tabKey}HasLastPage`]: hasLastPage });
335
335
  return;
336
336
  }
337
337
  const total = this.store.total || 0;
@@ -352,8 +352,9 @@ export class PageDataInstance<
352
352
  }
353
353
  this.store.loading.loadMore = true;
354
354
  // 判断是否最后一页数据
355
- this._setValues({ page: nextPage, hasLastPage });
356
- this.main_getList();
355
+ this._setValues({ page: nextPage });
356
+ await this.main_getList();
357
+ this._setValues({ hasLastPage });
357
358
  };
358
359
  }
359
360