@kengic/uni 0.6.3-beta.2 → 0.6.3-beta.20

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.
@@ -3,7 +3,17 @@
3
3
  <UniPopupDialog :before-close="true" title="选择工作站" @close="onClose" @confirm="onOk">
4
4
  <div class="row">
5
5
  <div class="label">工作站:</div>
6
- <div class="value">
6
+ <div class="value devcod">
7
+ <UniEasyinput
8
+ v-model="devcodInputValue"
9
+ :focus="isFocusMap.devcodInputValue"
10
+ :placeholder="currentDevcodDsc"
11
+ :placeholder-style="devcodPlaceholderStyle"
12
+ trim
13
+ @blur="onDevcodInputValueBlur"
14
+ @focus="onDevcodInputValueFocus"
15
+ @confirm="findDevmstByInputValue"
16
+ />
7
17
  <UniDataSelect :localdata="stationDatas" v-model="currentDevcod" :clear="true" />
8
18
  </div>
9
19
  </div>
@@ -18,8 +28,8 @@
18
28
  </template>
19
29
 
20
30
  <script lang="ts" setup>
21
- import { UniDataSelect, UniPopup, UniPopupDialog } from '../../uni';
22
- import { computed, ref, watch } from 'vue';
31
+ import { UniDataSelect, UniEasyinput, UniPopup, UniPopupDialog } from '../../uni';
32
+ import { computed, nextTick, ref, watch } from 'vue';
23
33
  import { useKgStation } from './index.hooks';
24
34
  import { WorkstationDTO } from '../../api/WMS/models';
25
35
  import { API } from '../../api';
@@ -41,24 +51,46 @@
41
51
  /** 所有工作站. */
42
52
  const stations = ref<Array<WorkstationDTO>>([]);
43
53
 
54
+ /**
55
+ * 工作站的输入框输入的值, 当输入框失去焦点或者回车时, 会根据这个值去匹配工作站编号, 如果匹配成功, 则选中该匹配的工作站, 否则清空该值并提升工作站不存在.
56
+ */
57
+ const devcodInputValue = ref('');
58
+
59
+ /**
60
+ * 工作站的输入框的占位符字符的样式.
61
+ */
62
+ const devcodPlaceholderStyle = ref('color: #3ee');
63
+
44
64
  /**
45
65
  * 工作站下拉列表.
46
66
  */
47
- const stationDatas = computed<Array<{ value: string; text: string }>>(() => stations.value.map((i) => ({ text: i.devcod ?? '', value: i.devcod ?? '' })));
67
+ const stationDatas = computed<Array<{ text: string; value: string }>>(() =>
68
+ stations.value.map((i) => ({ text: i.devcodDsc ?? i.devcod ?? '', value: i.devcod ?? '' })),
69
+ );
48
70
 
49
71
  /**
50
72
  * 工作区下拉列表.
51
73
  */
52
- const areaDatas = computed<Array<{ value: string; text: string }>>(
74
+ const areaDatas = computed<Array<{ text: string; value: string }>>(
53
75
  () =>
54
76
  stations.value
55
77
  .find((i) => i.devcod === currentDevcod.value)
56
- ?.workstationAreas?.map((i) => ({
78
+ ?.workstationAndAreaRelationshipDTOList?.map((i) => ({
57
79
  text: i.wrkareDsc ?? i.wrkare ?? '',
58
80
  value: i.wrkare ?? '',
59
81
  })) ?? [],
60
82
  );
61
83
 
84
+ /**
85
+ * 当前选择的工作站编号的描述.
86
+ */
87
+ const currentDevcodDsc = computed(() => stationDatas.value.find((i) => i.value === currentDevcod.value)?.text ?? '');
88
+
89
+ /**
90
+ * <p>是否聚焦.</p>
91
+ * <p>每个 key 对应一个输入框, 每个 value 表示该输入框当前是否聚焦.</p>
92
+ */
93
+ const isFocusMap = ref({ devcodInputValue: true });
62
94
  // ----------------------------------------------------------------------------------------------------
63
95
  //endregion
64
96
 
@@ -69,12 +101,10 @@
69
101
  if (!value) {
70
102
  currentHmewrkare.value = '';
71
103
  } else {
72
- console.log('11', value, currentDevcod.value);
73
104
  // 当「当前选择的工作站编号」变更时, 选择它的默认的工作区,
74
105
  const currentStation = stations.value.find((i) => i.devcod === currentDevcod.value);
75
106
  if (currentStation) {
76
107
  currentHmewrkare.value = currentStation.hmewrkare ?? '';
77
- console.log('22', currentHmewrkare.value);
78
108
  }
79
109
  }
80
110
  });
@@ -83,6 +113,57 @@
83
113
 
84
114
  //region FUNCTION
85
115
  // ----------------------------------------------------------------------------------------------------
116
+ /**
117
+ * 设置聚焦.
118
+ *
119
+ * @param key 要聚焦哪个输入框.
120
+ */
121
+ function setFocus(key: string) {
122
+ // 错误的输入框,
123
+ if (!key || !(key in isFocusMap.value)) {
124
+ return;
125
+ }
126
+
127
+ Object.keys(isFocusMap.value).forEach((key) => (isFocusMap.value[key] = false));
128
+ nextTick().then(() => (isFocusMap.value[key] = true));
129
+ }
130
+
131
+ /**
132
+ * 工作站的输入框失去焦点.
133
+ */
134
+ async function onDevcodInputValueBlur() {
135
+ devcodPlaceholderStyle.value = 'color: #333';
136
+
137
+ await nextTick();
138
+ await findDevmstByInputValue();
139
+ }
140
+
141
+ /**
142
+ * 工作站的输入框聚焦.
143
+ */
144
+ function onDevcodInputValueFocus() {
145
+ devcodPlaceholderStyle.value = 'color: #999';
146
+ }
147
+
148
+ /**
149
+ * 根据输入的值(作为工作站编号), 查找工作站.
150
+ */
151
+ async function findDevmstByInputValue() {
152
+ if (!devcodInputValue.value) {
153
+ return;
154
+ }
155
+
156
+ const station = stations.value.find((i) => i.devcod === devcodInputValue.value);
157
+ if (station) {
158
+ currentDevcod.value = devcodInputValue.value;
159
+ devcodInputValue.value = '';
160
+ } else {
161
+ devcodInputValue.value = '';
162
+ await uni.showToast({ icon: 'none', title: '工作站不存在' });
163
+ setFocus('devcodInputValue');
164
+ }
165
+ }
166
+
86
167
  /**
87
168
  * 取消.
88
169
  */
@@ -121,7 +202,15 @@
121
202
  */
122
203
  async function requestStations(): Promise<void> {
123
204
  try {
124
- stations.value = (await API.WMS.WorkstationController.List({ params: { pageNo: 1, pageSize: 999 } }))?.records ?? [];
205
+ stations.value =
206
+ (
207
+ await API.WMS.WorkstationController.List({
208
+ params: {
209
+ pageNo: 1,
210
+ pageSize: 999,
211
+ },
212
+ })
213
+ )?.records ?? [];
125
214
  } catch (e) {
126
215
  console.error(e);
127
216
  }
@@ -133,7 +222,12 @@
133
222
  </script>
134
223
 
135
224
  <style scoped>
225
+ :deep(.uni-popup__wrapper) {
226
+ width: calc(100% - 8px);
227
+ }
228
+
136
229
  :deep(.uni-popup-dialog) {
230
+ width: 100%;
137
231
  font-size: 13px;
138
232
  }
139
233
 
@@ -173,4 +267,21 @@
173
267
  flex: 1;
174
268
  min-width: 0;
175
269
  }
270
+
271
+ :deep(.uni-popup-dialog) .uni-dialog-content > .row > .value.devcod {
272
+ position: relative;
273
+ }
274
+
275
+ :deep(.uni-popup-dialog) .uni-dialog-content > .row > .value.devcod > .uni-easyinput {
276
+ color: rgb(51, 51, 51);
277
+ position: absolute;
278
+ left: 0;
279
+ top: 0;
280
+ z-index: 2;
281
+ width: calc(100% - 26px);
282
+ }
283
+
284
+ :deep(.uni-popup-dialog) .uni-dialog-content > .row > .value.devcod > .uni-easyinput > .uni-easyinput__content {
285
+ border-radius: 3px 0 0 3px;
286
+ }
176
287
  </style>
@@ -66,4 +66,14 @@ export enum KG_HTTP_HEADERS {
66
66
  * 仓库编号.
67
67
  */
68
68
  KG_WAREHOUSE = 'Kg-Warehouse',
69
+
70
+ /**
71
+ * 工作站.
72
+ */
73
+ KG_WORK_STATION = 'Kg-Work-Station',
74
+
75
+ /**
76
+ * 工作区.
77
+ */
78
+ KG_WORK_AREA = 'Kg-Work-Area',
69
79
  }
package/dist/index.css CHANGED
@@ -2,13 +2,32 @@ uni-button {
2
2
  border-radius: 3px !important;
3
3
  }
4
4
 
5
+ uni-button:after {
6
+ border-radius: 6px !important;
7
+ }
8
+
5
9
  .kg-tab-bar-sibling {
6
10
  padding-bottom: 50px !important;
7
11
  }
8
12
 
9
- .uni-simple-toast__text {
10
- padding: 6.5px 12px 9.5px 12px;
13
+ :deep(uni-toast) {
14
+ display: flex;
15
+ align-items: center;
16
+ justify-content: center;
17
+ }
18
+
19
+ :deep(uni-toast) .uni-sample-toast {
20
+ max-width: calc(100% - 6px);
21
+ position: relative;
22
+ top: initial;
23
+ left: initial;
24
+ transform: translate(0, 0);
25
+ }
26
+
27
+ :deep(uni-toast) .uni-sample-toast .uni-simple-toast__text {
28
+ padding: 7px 8px 9px 8px;
11
29
  border-radius: 4px;
30
+ background-color: rgba(17, 17, 17, 0.9);
12
31
  }
13
32
 
14
33
  /* #ifdef H5 */
@@ -2,6 +2,8 @@ import { useAppStore } from '../store/app.store';
2
2
  import { Kg } from '../util';
3
3
  import { KG_DYNAMIC_QUERY_OPERATOR, KG_HTTP_HEADERS } from '../const';
4
4
  import { useKgWarehouse } from '../component/KgWarehouse/index.hooks';
5
+ import { useKgStation } from '../component/KgStation';
6
+ import { isNil } from 'lodash-es';
5
7
 
6
8
  /*
7
9
  * 对请求做统一的拦截.
@@ -13,7 +15,7 @@ uni.addInterceptor('request', {
13
15
  const appStore = useAppStore();
14
16
 
15
17
  args.header['Authorization'] = appStore.getToken;
16
- // TODO 支持其他语言
18
+ // TODO LT 支持其他语言
17
19
  args.header['Accept-Language'] = 'zh_CN'.replace('_', '-');
18
20
  args.header['X-Access-Token'] = appStore.getToken;
19
21
 
@@ -68,9 +70,20 @@ type IRequestOptions = Omit<UniApp.RequestOptions, 'url'> & {
68
70
  */
69
71
  dynamicQueryOperatorModel?: Record<string, KG_DYNAMIC_QUERY_OPERATOR>;
70
72
 
71
- /** 是否不显示错误消息提示. */
73
+ /**
74
+ * 是否不显示错误消息提示.
75
+ *
76
+ * @default false
77
+ */
72
78
  isSuppressError?: boolean;
73
79
 
80
+ /**
81
+ * 是否不显示成功消息提示.
82
+ *
83
+ * @default false
84
+ */
85
+ isSuppressSuccess?: boolean;
86
+
74
87
  /** 是否处理请求结果. */
75
88
  isTransformResponse?: boolean;
76
89
 
@@ -100,6 +113,13 @@ function handleSuccess<T = any>(
100
113
  reject: (reason?: any) => void,
101
114
  options?: IRequestOptions,
102
115
  ) {
116
+ // 显示后端成功消息
117
+ if (!options?.isSuppressSuccess) {
118
+ if ((response.data as any).message) {
119
+ uni.showToast({ duration: 1000 * 3, icon: 'none', title: (response.data as any).message });
120
+ }
121
+ }
122
+
103
123
  if (options?.isTransformResponse === false) {
104
124
  resolve(response.data as any);
105
125
  } else {
@@ -129,7 +149,7 @@ function handleError<T = any>(
129
149
  if (!isSuppressError) {
130
150
  // @ts-ignore
131
151
  const message = (response.data as any)?.message || response?.errMsg || '请求出错';
132
- uni.showToast({ title: message, icon: 'none', duration: 3000 });
152
+ uni.showToast({ duration: 3000, icon: 'none', title: message });
133
153
  }
134
154
 
135
155
  reject(response);
@@ -160,14 +180,15 @@ const _httpClient: IHttpClient = {
160
180
  if (['POST', 'PUT', 'DELETE'].includes(method) && params) {
161
181
  try {
162
182
  const queryString = Object.keys(params)
163
- // @ts-ignore
164
- .map((i) => i + '=' + options.params[i])
183
+ // 值为 null/undefined 的参数, 不需要放到 query 参数中去,
184
+ .filter((i) => !isNil(params[i]))
185
+ .map((i) => i + '=' + params[i])
165
186
  .join('&');
166
187
  if (queryString) {
167
188
  _url += '?' + queryString;
168
189
  }
169
190
  } catch (e) {
170
- console.log(e);
191
+ console.error(e);
171
192
  }
172
193
  }
173
194
 
@@ -177,13 +198,6 @@ const _httpClient: IHttpClient = {
177
198
  header = {};
178
199
  }
179
200
 
180
- const KG_IS_DYNAMIC_QUERY = KG_HTTP_HEADERS.KG_IS_DYNAMIC_QUERY;
181
- const KG_QUERY_WHERE_SQL = KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL;
182
- const KG_QUERY_ORDER_BY_SQL = KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL;
183
- const KG_QUERY_OFFSET_SQL = KG_HTTP_HEADERS.KG_QUERY_OFFSET_SQL;
184
- const KG_QUERY_SQL = KG_HTTP_HEADERS.KG_QUERY_SQL;
185
- const KG_QUERY_OPERATOR = KG_HTTP_HEADERS.KG_QUERY_OPERATOR;
186
-
187
201
  // 启用高级查询
188
202
  if (options?.dynamicQueryOperatorModel) {
189
203
  let params: any = {};
@@ -199,39 +213,28 @@ const _httpClient: IHttpClient = {
199
213
  const { sql, whereSql, orderBySql, offsetSql, operatorJSON } = Kg.getQueryHeaders({
200
214
  dynamicQueryExcludeProperties: options?.dynamicQueryExcludeProperties,
201
215
  dynamicQueryOperatorModel: options?.dynamicQueryOperatorModel,
202
- params: params,
216
+ params: Kg.parseParams(params),
203
217
  });
204
218
 
205
219
  header = {
206
220
  ...(header ?? {}),
207
- [KG_IS_DYNAMIC_QUERY]: true,
208
- [KG_QUERY_OFFSET_SQL]: offsetSql,
209
- [KG_QUERY_OPERATOR]: operatorJSON,
210
- [KG_QUERY_ORDER_BY_SQL]: orderBySql,
211
- [KG_QUERY_SQL]: sql,
212
- [KG_QUERY_WHERE_SQL]: whereSql,
221
+ [KG_HTTP_HEADERS.KG_IS_DYNAMIC_QUERY]: true,
222
+ [KG_HTTP_HEADERS.KG_QUERY_OFFSET_SQL]: offsetSql,
223
+ [KG_HTTP_HEADERS.KG_QUERY_OPERATOR]: operatorJSON,
224
+ [KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL]: orderBySql,
225
+ [KG_HTTP_HEADERS.KG_QUERY_SQL]: sql,
226
+ [KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL]: whereSql,
213
227
  };
214
228
  }
215
229
 
216
- if (header[KG_QUERY_WHERE_SQL]) {
217
- header[KG_QUERY_WHERE_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_QUERY_WHERE_SQL])));
218
- }
219
-
220
- if (header[KG_QUERY_ORDER_BY_SQL]) {
221
- header[KG_QUERY_ORDER_BY_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_QUERY_ORDER_BY_SQL])));
222
- }
223
-
224
- if (header[KG_QUERY_OFFSET_SQL]) {
225
- header[KG_QUERY_OFFSET_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_QUERY_OFFSET_SQL])));
226
- }
227
-
228
- if (header[KG_QUERY_SQL]) {
229
- header[KG_QUERY_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_QUERY_SQL])));
230
- }
230
+ header[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_HTTP_HEADERS.KG_QUERY_WHERE_SQL] ?? '')));
231
+ header[KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_HTTP_HEADERS.KG_QUERY_ORDER_BY_SQL] ?? '')));
232
+ header[KG_HTTP_HEADERS.KG_QUERY_OFFSET_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_HTTP_HEADERS.KG_QUERY_OFFSET_SQL] ?? '')));
233
+ header[KG_HTTP_HEADERS.KG_QUERY_SQL] = encodeURIComponent(decodeURIComponent(String(header[KG_HTTP_HEADERS.KG_QUERY_SQL] ?? '')));
231
234
 
232
- // 仓库编号
233
- const warehouseId = useKgWarehouse().warehouse.value?.whId ?? '';
234
- header[KG_HTTP_HEADERS.KG_WAREHOUSE] = encodeURIComponent(warehouseId);
235
+ header[KG_HTTP_HEADERS.KG_WAREHOUSE] = encodeURIComponent(useKgWarehouse().warehouse.value?.whId ?? '');
236
+ header[KG_HTTP_HEADERS.KG_WORK_STATION] = encodeURIComponent(useKgStation().station.value?.devcod ?? '');
237
+ header[KG_HTTP_HEADERS.KG_WORK_AREA] = encodeURIComponent(useKgStation().station.value?.hmewrkare ?? '');
235
238
 
236
239
  uni.request({
237
240
  ...(options ?? {}),
@@ -239,31 +242,37 @@ const _httpClient: IHttpClient = {
239
242
  url: _url,
240
243
  header: header,
241
244
  data: { ...(params ?? {}), ...(data ?? {}) },
245
+ // 超时时间, 单位毫秒, 默认 60 秒,
246
+ timeout: 1000 * 60 * 60,
242
247
  success(response) {
243
248
  switch (response.statusCode) {
244
249
  case 200:
245
250
  if (typeof response.data === 'string') {
246
251
  // 接口返回的数据是 HTML, 退出登录
247
252
  if (response.data.startsWith('<!DOCTYPE')) {
248
- // store.dispatch('logout');
249
253
  }
250
254
  } else if (response.data instanceof ArrayBuffer) {
255
+ // 文件
251
256
  } else {
252
- // 处理自定义的错误码
253
- switch (response.data.code) {
254
- case 0:
255
- case 200:
256
- handleSuccess<T>(response as any, resolve, reject, options);
257
- break;
258
-
259
- case 405:
260
- response.data.message = `${response.data.code}: ${response.data.message}`;
261
- handleError<T>(response, resolve, reject, options?.isSuppressError ?? false);
262
- break;
263
-
264
- case 500:
265
- handleError<T>(response, resolve, reject, options?.isSuppressError ?? false);
266
- break;
257
+ if (response.data.success === false) {
258
+ handleError<T>(response, resolve, reject, options?.isSuppressError ?? false);
259
+ } else {
260
+ // 处理自定义的错误码
261
+ switch (response.data.code) {
262
+ case 0:
263
+ case 200:
264
+ handleSuccess<T>(response as any, resolve, reject, options);
265
+ break;
266
+
267
+ case 405:
268
+ response.data.message = `${response.data.code}: ${response.data.message}`;
269
+ handleError<T>(response, resolve, reject, options?.isSuppressError ?? false);
270
+ break;
271
+
272
+ case 500:
273
+ handleError<T>(response, resolve, reject, options?.isSuppressError ?? false);
274
+ break;
275
+ }
267
276
  }
268
277
  }
269
278
  break;
@@ -7,7 +7,7 @@
7
7
  <view v-if="current" class="uni-select__input-text">{{ textShow }}</view>
8
8
  <view v-else class="uni-select__input-text uni-select__input-placeholder">{{ typePlaceholder }} </view>
9
9
  <view v-if="current && clear && !disabled" @click.stop="clearVal">
10
- <uni-icons type="clear" color="#c0c4cc" size="14" />
10
+ <uni-icons type="clear" color="#c0c4cc" size="16" />
11
11
  </view>
12
12
  <view v-else style="display: flex; align-items: center; justify-content: center">
13
13
  <view :class="showSelector ? 'ant-design--caret-up-filled' : 'ant-design--caret-down-filled'" />
@@ -140,7 +140,7 @@
140
140
  textShow() {
141
141
  // 长文本显示
142
142
  let text = this.current;
143
- if (text.length > 10) {
143
+ if (text.length > 999) {
144
144
  return text.slice(0, 25) + '...';
145
145
  }
146
146
  return text;
@@ -399,6 +399,7 @@
399
399
  flex: 1;
400
400
  flex-direction: row;
401
401
  align-items: center;
402
+ overflow: hidden;
402
403
  }
403
404
 
404
405
  .uni-select__input {
@@ -23,6 +23,7 @@ export const debounce = function (func, wait = 1000, immediate = true) {
23
23
  }
24
24
  };
25
25
  };
26
+
26
27
  /**
27
28
  * @desc 函数节流
28
29
  * @param func 函数