@tmsfe/tms-core 0.0.213 → 0.0.215

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.213",
3
+ "version": "0.0.215",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/request.js CHANGED
@@ -235,6 +235,21 @@ export default class Request {
235
235
  return `${validHost}/${path}`;
236
236
  };
237
237
 
238
+ /**
239
+ * 准备请求数据(包含参数组装和签名)
240
+ * @public
241
+ * @memberof Request
242
+ * @param {Object} param 业务参数
243
+ * @returns {Promise<Object>} 处理后的请求数据(包含签名)
244
+ * @example
245
+ * const request = tms.createRequest();
246
+ * const requestData = await request.prepareRequestData({ userId: 123 });
247
+ */
248
+ async prepareRequestData(param = {}) {
249
+ const requestParam = await composeParam(param, this.withAuth, this.baseParam);
250
+ return sign(requestParam, this.secretKey);
251
+ }
252
+
238
253
  /**
239
254
  * @public
240
255
  * @memberof Request
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @desc: 异步组件Behavior
3
+ * 父组件和子组件中都需要注册
4
+ */
5
+
6
+ const getPromiseName = id => `__comLoadPromise_${id}`;
7
+ const getResolveName = id => `__comLoadPromiseResolve_${id}`;
8
+
9
+ const asyncSelectBehavior = Behavior({
10
+ lifetimes: {
11
+ attached() {
12
+ if (!this.id) {
13
+ return;
14
+ }
15
+ const owner = this.selectOwnerComponent();
16
+ // 组件加载完毕向父组件标记自己加载完毕
17
+ if (owner) {
18
+ const id = `#${this.id}`;
19
+ const promiseName = getPromiseName(id);
20
+ const resolveName = getResolveName(id);
21
+ // 父组件调用asyncSelectComponent时才创建promise桥梁,这里可能创建了,可能没有
22
+ if (owner[resolveName] === undefined) {
23
+ owner[promiseName] = Promise.resolve(this);
24
+ } else {
25
+ owner[resolveName](this);
26
+ }
27
+ }
28
+ },
29
+ },
30
+ methods: {
31
+ // 异步组件selectComponent函数,父组件调用
32
+ asyncSelectComponent(id, opts = {}) {
33
+ const { cache = true } = opts;
34
+ const promiseName = getPromiseName(id);
35
+ if (cache && this[promiseName] !== undefined) {
36
+ return this[promiseName];
37
+ }
38
+ this[promiseName] = new Promise((resolve) => {
39
+ this[getResolveName(id)] = resolve;
40
+ });
41
+ return this[promiseName];
42
+ },
43
+ },
44
+ });
45
+
46
+
47
+ module.exports = asyncSelectBehavior;