nvue3 1.1.11 → 1.1.12

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.
@@ -35,7 +35,7 @@
35
35
  </template>
36
36
 
37
37
  <script setup>
38
- import { computed, ref, inject, onMounted } from 'vue';
38
+ import { computed, ref, inject, onMounted, isRef, isReactive } from 'vue';
39
39
  import { onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
40
40
  const { back } = inject('$pages');
41
41
  const { post } = inject('$http');
@@ -120,7 +120,7 @@
120
120
  */
121
121
  const request = (refresh, option = {}) => {
122
122
  const index = refresh ? 1 : (pageIndex.value + 1)
123
-
123
+ const loaded = Boolean(option.loaded || false);
124
124
  post(api, Object.assign({}, params, option, { index })).then(
125
125
  res => {
126
126
  uni.stopPullDownRefresh();
@@ -128,13 +128,14 @@
128
128
 
129
129
  const resData = (field ? res.data[field] : res.data) || [];
130
130
  if (refresh) {
131
+ datas.value.length = 0;
131
132
  if (resData.length > 0) datas.value = [...resData];
132
133
  else datas.value.length = 0;
133
134
  }
134
135
  else if (resData.length > 0) {
135
136
  datas.value.push(...resData);
136
137
  }
137
- emit('update', res.data, refresh);
138
+ emit('update', res.data, refresh, loaded);
138
139
 
139
140
  pageState.value = 1;
140
141
  pageIndex.value = paging.value.index;
@@ -164,7 +165,11 @@
164
165
  request(true, { loaded: 1 });
165
166
 
166
167
  if (!listen) return;
167
- uni.$on(listen, () => { request(true, {}) });
168
+ uni.$off(listen);
169
+ uni.$on(listen, (...from) => {
170
+ console.log(`by paging listen(${listen})=======>`, from);
171
+ request(true, {})
172
+ });
168
173
 
169
174
  })
170
175
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nvue3",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "for uniapp & vue3",
5
5
  "main": "src/kernel.js",
6
6
  "scripts": {
package/src/http.js CHANGED
@@ -2,8 +2,8 @@
2
2
  * toast最少显示长时间,主要是加载api的读取中后续关闭
3
3
  */
4
4
  const tstShow = 350;
5
- // const isDebug = (process.env.NODE_ENV === 'development');
6
- const isDebug = true;
5
+ const isDebug = (process.env.NODE_ENV === 'development');
6
+ // const isDebug = true;
7
7
 
8
8
  const baseResp = {
9
9
  success: 1,
@@ -18,6 +18,7 @@ const config = {
18
18
  modal: false, //出错时显示model,否则显示toast
19
19
  timeout: 6000,
20
20
  mintime: 100, //两次modal或toast之间间隔最短时间,小于此时间的不显示
21
+ detection: 0, //检测相同API连续请求间隔,小于此时间的报错,0不检测
21
22
  toast: {
22
23
  'l': '加载中...',
23
24
  'r': '读取中...',
@@ -312,10 +313,6 @@ function doComplete(request, res, resolve, reject) {
312
313
  request.timer.used = request.timer.after - request.timer.before;
313
314
  request.timer.useTime = (request.timer.used / 1000) + 's';
314
315
 
315
- /**
316
- * 1727661448.089
317
- */
318
-
319
316
  if (request.toast && (tstShow > 0)) {
320
317
  if (request.timer.used > tstShow) {
321
318
  if (request.loading) uni.hideLoading();
@@ -327,7 +324,7 @@ function doComplete(request, res, resolve, reject) {
327
324
  }
328
325
  }
329
326
 
330
- if (isDebug) console.log(request)
327
+ if (isDebug || config.debug) console.log(request)
331
328
  }
332
329
 
333
330
 
@@ -461,7 +458,7 @@ function doUpload_OLD(request, choose) {
461
458
  formData: request.request,
462
459
  files: files,
463
460
  success: (res) => {
464
- if (isDebug) console.log(res);
461
+ console.log(res);
465
462
  try {
466
463
  if (typeof res.data === 'string') res.data = JSON.parse(res.data);
467
464
  }
@@ -507,7 +504,7 @@ function doUpload_OLD(request, choose) {
507
504
  doSuccess(request, resp);
508
505
  },
509
506
  allError => {
510
- if (isDebug) console.log('allError', allError);
507
+ console.log('allError', allError);
511
508
  doFail(request, allError[0]);
512
509
  });
513
510
  //#endif
@@ -624,10 +621,9 @@ function FrequencyDetection(api) {
624
621
  if (api[0] === '@') return null; //不检查频率
625
622
 
626
623
  let nowTime = Date.now();
627
- console.log({ api, nowTime, justPostTime });
628
624
 
629
- if (api === justPostApi && nowTime - justPostTime < config.mintime) {
630
- console.log({ nowTime, justPostTime, just: nowTime - justPostTime, min: config.mintime });
625
+ if (api === justPostApi && nowTime - justPostTime < config.detection) {
626
+ // console.log({ nowTime, justPostTime, just: nowTime - justPostTime, detection: config.detection });
631
627
 
632
628
  return new Promise((resolve, reject) => {
633
629
  reject({
@@ -655,15 +651,19 @@ export default class {
655
651
  }
656
652
 
657
653
  get(api, data = {}) {
658
- const fd = FrequencyDetection(api);
659
- if (fd) return fd;
654
+ if (config.detection > 0) {
655
+ const fd = FrequencyDetection(api);
656
+ if (fd) return fd;
657
+ }
660
658
 
661
659
  return doRequest(new _request(api, data, 'get'));
662
660
  }
663
661
 
664
662
  post(api, data = {}) {
665
- const fd = FrequencyDetection(api);
666
- if (fd) return fd;
663
+ if (config.detection > 0) {
664
+ const fd = FrequencyDetection(api);
665
+ if (fd) return fd;
666
+ }
667
667
 
668
668
  return doRequest(new _request(api, data, 'post'));
669
669
  }