centaline-data-driven-v3 0.0.67 → 0.0.68

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": "centaline-data-driven-v3",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "private": false,
5
5
  "description": "centaline-data-driven-v3",
6
6
  "main": "dist/centaline-data-driven-v3.umd.js",
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <ct-field :vmodel="model">
3
3
  <template #Control>
4
- <el-select-v2 ref="refselect" :key="itemKey" v-model="model.value" :options="model.options"
4
+ <el-select-v2 ref="refselect" :key="model.itemKey" v-model="model.value" :options="model.options"
5
5
  :props="model.optionAttrs" v-bind="model.attrs" :disabled="model.locked" clearable @change="change"
6
6
  :placeholder="model.placeholder" @visible-change="visibleChange" @clear="clear"
7
7
  :filterable="model.filterable" :multiple="model.multiple" class="fieldControl" :height="300"
@@ -44,6 +44,7 @@
44
44
  </ct-field>
45
45
  </template>
46
46
  <script lang="ts" setup>
47
+ import Axios from 'axios';
47
48
  import { ref, nextTick } from 'vue'
48
49
  import { Search } from '@element-plus/icons-vue'
49
50
  import { initData, changeHandler } from '../../utils/mixins';
@@ -57,8 +58,9 @@ const props = defineProps({
57
58
  const model = initData(props, ComboBox)
58
59
  const refselect = ref()
59
60
  const open = ref(false)
60
- const itemKey = ref(Math.random())
61
61
  const isComposing = ref(false);
62
+ model.value.itemKey=Math.random();
63
+ let cancelTokenSource = null; // 用于存储取消令牌
62
64
 
63
65
  //下拉框出现/隐藏时触发
64
66
  function visibleChange(visible) {
@@ -81,8 +83,15 @@ function visibleChange(visible) {
81
83
  }
82
84
  //获取数据列表
83
85
  function getOptions(key) {
86
+ if (cancelTokenSource) {
87
+ // 取消上一次未完成的请求
88
+ cancelTokenSource.cancel('取消上一次请求');
89
+ }
90
+
91
+ // 创建新的取消令牌
92
+ cancelTokenSource = Axios.CancelToken.source();
84
93
  if (!isComposing.value &&!model.value.moreActionRouter) {
85
- model.value.getOptions(props.parameterAction, key, function (data) {
94
+ model.value.getOptions(props.parameterAction, key,cancelTokenSource, function (data) {
86
95
  if(data){
87
96
  data.forEach((v) => {
88
97
  let item = model.value.globalOptions.find((v1) => {
@@ -141,7 +150,7 @@ function change(val) {
141
150
  if (model.value.defaultCode1) {
142
151
  val = model.value.defaultCode1
143
152
  model.value.value = val
144
- itemKey.value = Math.random()
153
+ model.value.itemKey = Math.random()
145
154
  }
146
155
  }
147
156
  model.value.setcode(val)
@@ -160,7 +160,7 @@ const ComboBox = function (source) {
160
160
  }
161
161
  return source.code1 === '' ? [] : [{ value: source.code1, label: source.name1 }]
162
162
  },
163
- getOptions(paramsAction, searchText, CallBack) {
163
+ getOptions(paramsAction, searchText, cancelTokenSource,CallBack) {
164
164
  var apiAddrs = paramsAction;
165
165
  var params = {
166
166
  action: apiAddrs,
@@ -171,7 +171,7 @@ const ComboBox = function (source) {
171
171
  key: searchText
172
172
  }
173
173
  };
174
- request.postHandler(common.globalUri(), params).then((response) => {
174
+ request.postTokenHandler(common.globalUri(), params,cancelTokenSource).then((response) => {
175
175
  if (response.rtnCode === 200) {
176
176
  if (CallBack) {
177
177
  CallBack(response.content)
@@ -109,9 +109,9 @@ function loadFromModel(source, isFormList) {
109
109
  rtn1["options"][0]["value"] = attrValue
110
110
  }
111
111
  if (attrKey == 'name1') {
112
- rtn1["name1"] = attrValue;
113
112
  rtn1["options"][0]["label"] = attrValue
114
113
  }
114
+ if(rtn1.itemKey)rtn1.itemKey=Math.random()
115
115
  }
116
116
  hiddenHandle(rtn1, this.form);
117
117
  requiredHandle(rtn1, this.form);
@@ -490,7 +490,7 @@ function addRow(model) {
490
490
  "buttonType": Enum.ButtonType.Submit
491
491
  }
492
492
  ],
493
- actionRouters: model.actionRouters,
493
+ actionRouters: model.source.actionRouters,
494
494
  },
495
495
  parentModelForm: model.parentModel,
496
496
  relationParentFormFields:model.getRelationParentFormFields(),
@@ -119,7 +119,7 @@ const request = {
119
119
  return Promise.reject(response);
120
120
  }
121
121
  //返回给下一个链式调用
122
- return Promise.resolve(response.data,response.headers);
122
+ return Promise.resolve(response.data, response.headers);
123
123
  },
124
124
  postHandler(url, params, scripts) {
125
125
  if (params.action.indexOf('http://') > -1 || params.action.indexOf('https://') > -1) {
@@ -168,6 +168,33 @@ const request = {
168
168
  return Promise.resolve(ex);//错误处理了,直接返回成功,要判断response.rtnCode=200再处理
169
169
  });
170
170
  },
171
+ //有新请求关闭上一次请求
172
+ postTokenHandler(url, params, cancelTokenSource) {
173
+ if (params.action.indexOf('http://') > -1 || params.action.indexOf('https://') > -1) {
174
+ url = params.action;
175
+ params = params.para;
176
+ }
177
+ else if (common.flagRouterSelf()) {
178
+ url = url + params.action;
179
+ params = params.para;
180
+ }
181
+ return Axios.post(url, params, {
182
+ headers: common.getDataDrivenOpts().handler.getRequestHeaders(),
183
+ cancelToken: cancelTokenSource.token, // 传递取消令牌
184
+ }).then((response) => {
185
+ return this.postThenHandler(response);
186
+ }).catch((ex) => {
187
+ if (!Axios.isCancel(ex)) {
188
+ if (ex.message) {
189
+ common.message(ex.message, 'error')
190
+ }
191
+ else if (typeof ex.data === "string") {
192
+ common.message(ex.data, 'error')
193
+ }
194
+ }
195
+ return Promise.resolve(ex.data ? ex.data : ex);//错误处理了,直接返回成功,要判断response.rtnCode=200再处理
196
+ });
197
+ },
171
198
  };
172
199
  request.install = function (app) {
173
200
  app.config.globalProperties.$request = request;