@kengic/uni 0.3.3-beta.1 → 0.3.3

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.
@@ -1,275 +1,272 @@
1
1
  <template>
2
- <view class="uni-popup-dialog">
3
- <view class="uni-dialog-title">
4
- <text class="uni-dialog-title-text" :class="['uni-popup__'+dialogType]">{{titleText}}</text>
5
- </view>
6
- <view v-if="mode === 'base'" class="uni-dialog-content">
7
- <slot>
8
- <text class="uni-dialog-content-text">{{content}}</text>
9
- </slot>
10
- </view>
11
- <view v-else class="uni-dialog-content">
12
- <slot>
13
- <input class="uni-dialog-input" v-model="val" :type="inputType" :placeholder="placeholderText" :focus="focus" >
14
- </slot>
15
- </view>
16
- <view class="uni-dialog-button-group">
17
- <view class="uni-dialog-button" @click="closeDialog">
18
- <text class="uni-dialog-button-text">{{closeText}}</text>
19
- </view>
20
- <view class="uni-dialog-button uni-border-left" @click="onOk">
21
- <text class="uni-dialog-button-text uni-button-color">{{okText}}</text>
22
- </view>
23
- </view>
24
-
25
- </view>
2
+ <view class="uni-popup-dialog">
3
+ <view class="uni-dialog-title">
4
+ <text class="uni-dialog-title-text" :class="['uni-popup__' + dialogType]">{{ titleText }}</text>
5
+ </view>
6
+ <view v-if="mode === 'base'" class="uni-dialog-content">
7
+ <slot>
8
+ <text class="uni-dialog-content-text">{{ content }}</text>
9
+ </slot>
10
+ </view>
11
+ <view v-else class="uni-dialog-content">
12
+ <slot>
13
+ <input class="uni-dialog-input" v-model="val" :type="inputType" :placeholder="placeholderText" :focus="focus" />
14
+ </slot>
15
+ </view>
16
+ <view class="uni-dialog-button-group">
17
+ <view class="uni-dialog-button" @click="closeDialog">
18
+ <text class="uni-dialog-button-text">{{ closeText }}</text>
19
+ </view>
20
+ <view class="uni-dialog-button uni-border-left" @click="onOk">
21
+ <text class="uni-dialog-button-text uni-button-color">{{ okText }}</text>
22
+ </view>
23
+ </view>
24
+ </view>
26
25
  </template>
27
26
 
28
27
  <script>
29
- import popup from '../uni-popup/popup.js'
30
- import {
31
- initVueI18n
32
- } from '@dcloudio/uni-i18n'
33
- import messages from '../uni-popup/i18n'
34
- const { t } = initVueI18n(messages)
35
- /**
36
- * PopUp 弹出层-对话框样式
37
- * @description 弹出层-对话框样式
38
- * @tutorial https://ext.dcloud.net.cn/plugin?id=329
39
- * @property {String} value input 模式下的默认值
40
- * @property {String} placeholder input 模式下输入提示
41
- * @property {String} type = [success|warning|info|error] 主题样式
42
- * @value success 成功
43
- * @value warning 提示
44
- * @value info 消息
45
- * @value error 错误
46
- * @property {String} mode = [base|input] 模式、
47
- * @value base 基础对话框
48
- * @value input 可输入对话框
49
- * @property {String} content 对话框内容
50
- * @property {Boolean} beforeClose 是否拦截取消事件
51
- * @event {Function} confirm 点击确认按钮触发
52
- * @event {Function} close 点击取消按钮触发
53
- */
28
+ import popup from '../uni-popup/popup.js';
29
+ import { initVueI18n } from '@dcloudio/uni-i18n';
30
+ import messages from '../uni-popup/i18n';
31
+ const { t } = initVueI18n(messages);
32
+ /**
33
+ * PopUp 弹出层-对话框样式
34
+ * @description 弹出层-对话框样式
35
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=329
36
+ * @property {String} value input 模式下的默认值
37
+ * @property {String} placeholder input 模式下输入提示
38
+ * @property {String} type = [success|warning|info|error] 主题样式
39
+ * @value success 成功
40
+ * @value warning 提示
41
+ * @value info 消息
42
+ * @value error 错误
43
+ * @property {String} mode = [base|input] 模式、
44
+ * @value base 基础对话框
45
+ * @value input 可输入对话框
46
+ * @property {String} content 对话框内容
47
+ * @property {Boolean} beforeClose 是否拦截取消事件
48
+ * @event {Function} confirm 点击确认按钮触发
49
+ * @event {Function} close 点击取消按钮触发
50
+ */
54
51
 
55
- export default {
56
- name: "uniPopupDialog",
57
- mixins: [popup],
58
- emits:['confirm','close'],
59
- props: {
60
- inputType:{
61
- type: String,
62
- default: 'text'
63
- },
64
- value: {
65
- type: [String, Number],
66
- default: ''
67
- },
68
- placeholder: {
69
- type: [String, Number],
70
- default: ''
71
- },
72
- type: {
73
- type: String,
74
- default: 'error'
75
- },
76
- mode: {
77
- type: String,
78
- default: 'base'
79
- },
80
- title: {
81
- type: String,
82
- default: ''
83
- },
84
- content: {
85
- type: String,
86
- default: ''
87
- },
88
- beforeClose: {
89
- type: Boolean,
90
- default: false
91
- },
92
- cancelText:{
93
- type: String,
94
- default: ''
95
- },
96
- confirmText:{
97
- type: String,
98
- default: ''
99
- }
100
- },
101
- data() {
102
- return {
103
- dialogType: 'error',
104
- focus: false,
105
- val: ""
106
- }
107
- },
108
- computed: {
109
- okText() {
110
- return this.confirmText || t("uni-popup.ok")
111
- },
112
- closeText() {
113
- return this.cancelText || t("uni-popup.cancel")
114
- },
115
- placeholderText() {
116
- return this.placeholder || t("uni-popup.placeholder")
117
- },
118
- titleText() {
119
- return this.title || t("uni-popup.title")
120
- }
121
- },
122
- watch: {
123
- type(val) {
124
- this.dialogType = val
125
- },
126
- mode(val) {
127
- if (val === 'input') {
128
- this.dialogType = 'info'
129
- }
130
- },
131
- value(val) {
132
- this.val = val
133
- }
134
- },
135
- created() {
136
- // 对话框遮罩不可点击
137
- this.popup.disableMask()
138
- // this.popup.closeMask()
139
- if (this.mode === 'input') {
140
- this.dialogType = 'info'
141
- this.val = this.value
142
- } else {
143
- this.dialogType = this.type
144
- }
145
- },
146
- mounted() {
147
- this.focus = true
148
- },
149
- methods: {
150
- /**
151
- * 点击确认按钮
152
- */
153
- onOk() {
154
- if (this.mode === 'input'){
155
- this.$emit('confirm', this.val)
156
- }else{
157
- this.$emit('confirm')
158
- }
159
- if(this.beforeClose) return
160
- this.popup.close()
161
- },
162
- /**
163
- * 点击取消按钮
164
- */
165
- closeDialog() {
166
- this.$emit('close')
167
- if(this.beforeClose) return
168
- this.popup.close()
169
- },
170
- close(){
171
- this.popup.close()
172
- }
173
- }
174
- }
52
+ export default {
53
+ name: 'uniPopupDialog',
54
+ mixins: [popup],
55
+ emits: ['confirm', 'close'],
56
+ props: {
57
+ inputType: {
58
+ type: String,
59
+ default: 'text',
60
+ },
61
+ value: {
62
+ type: [String, Number],
63
+ default: '',
64
+ },
65
+ placeholder: {
66
+ type: [String, Number],
67
+ default: '',
68
+ },
69
+ type: {
70
+ type: String,
71
+ default: 'error',
72
+ },
73
+ mode: {
74
+ type: String,
75
+ default: 'base',
76
+ },
77
+ title: {
78
+ type: String,
79
+ default: '',
80
+ },
81
+ content: {
82
+ type: String,
83
+ default: '',
84
+ },
85
+ beforeClose: {
86
+ type: Boolean,
87
+ default: false,
88
+ },
89
+ cancelText: {
90
+ type: String,
91
+ default: '',
92
+ },
93
+ confirmText: {
94
+ type: String,
95
+ default: '',
96
+ },
97
+ },
98
+ data() {
99
+ return {
100
+ dialogType: 'error',
101
+ focus: false,
102
+ val: '',
103
+ };
104
+ },
105
+ computed: {
106
+ okText() {
107
+ return this.confirmText || t('uni-popup.ok');
108
+ },
109
+ closeText() {
110
+ return this.cancelText || t('uni-popup.cancel');
111
+ },
112
+ placeholderText() {
113
+ return this.placeholder || t('uni-popup.placeholder');
114
+ },
115
+ titleText() {
116
+ return this.title || t('uni-popup.title');
117
+ },
118
+ },
119
+ watch: {
120
+ type(val) {
121
+ this.dialogType = val;
122
+ },
123
+ mode(val) {
124
+ if (val === 'input') {
125
+ this.dialogType = 'info';
126
+ }
127
+ },
128
+ value(val) {
129
+ this.val = val;
130
+ },
131
+ },
132
+ created() {
133
+ // 对话框遮罩不可点击
134
+ this.popup.disableMask();
135
+ // this.popup.closeMask()
136
+ if (this.mode === 'input') {
137
+ this.dialogType = 'info';
138
+ this.val = this.value;
139
+ } else {
140
+ this.dialogType = this.type;
141
+ }
142
+ },
143
+ mounted() {
144
+ this.focus = true;
145
+ },
146
+ methods: {
147
+ /**
148
+ * 点击确认按钮
149
+ */
150
+ onOk() {
151
+ if (this.mode === 'input') {
152
+ this.$emit('confirm', this.val);
153
+ } else {
154
+ this.$emit('confirm');
155
+ }
156
+ if (this.beforeClose) return;
157
+ this.popup.close();
158
+ },
159
+ /**
160
+ * 点击取消按钮
161
+ */
162
+ closeDialog() {
163
+ this.$emit('close');
164
+ if (this.beforeClose) return;
165
+ this.popup.close();
166
+ },
167
+ close() {
168
+ this.popup.close();
169
+ },
170
+ },
171
+ };
175
172
  </script>
176
173
 
177
- <style lang="scss" >
178
- .uni-popup-dialog {
179
- width: 300px;
180
- border-radius: 11px;
181
- background-color: #fff;
182
- }
174
+ <style lang="scss">
175
+ .uni-popup-dialog {
176
+ width: 300px;
177
+ border-radius: 11px;
178
+ background-color: #fff;
179
+ }
183
180
 
184
- .uni-dialog-title {
185
- /* #ifndef APP-NVUE */
186
- display: flex;
187
- /* #endif */
188
- flex-direction: row;
189
- justify-content: center;
190
- padding-top: 25px;
191
- }
181
+ .uni-dialog-title {
182
+ /* #ifndef APP-NVUE */
183
+ display: flex;
184
+ /* #endif */
185
+ flex-direction: row;
186
+ justify-content: center;
187
+ padding-top: 25px;
188
+ }
192
189
 
193
- .uni-dialog-title-text {
194
- font-size: 16px;
195
- font-weight: 500;
196
- }
190
+ .uni-dialog-title-text {
191
+ font-size: 16px;
192
+ font-weight: 500;
193
+ }
197
194
 
198
- .uni-dialog-content {
199
- /* #ifndef APP-NVUE */
200
- display: flex;
201
- /* #endif */
202
- flex-direction: row;
203
- justify-content: center;
204
- align-items: center;
205
- padding: 20px;
206
- }
195
+ .uni-dialog-content {
196
+ /* #ifndef APP-NVUE */
197
+ display: flex;
198
+ /* #endif */
199
+ flex-direction: row;
200
+ justify-content: center;
201
+ align-items: center;
202
+ padding: 20px;
203
+ }
207
204
 
208
- .uni-dialog-content-text {
209
- font-size: 14px;
210
- color: #6C6C6C;
211
- }
205
+ .uni-dialog-content-text {
206
+ font-size: 14px;
207
+ color: #6c6c6c;
208
+ }
212
209
 
213
- .uni-dialog-button-group {
214
- /* #ifndef APP-NVUE */
215
- display: flex;
216
- /* #endif */
217
- flex-direction: row;
218
- border-top-color: #f5f5f5;
219
- border-top-style: solid;
220
- border-top-width: 1px;
221
- }
210
+ .uni-dialog-button-group {
211
+ /* #ifndef APP-NVUE */
212
+ display: flex;
213
+ /* #endif */
214
+ flex-direction: row;
215
+ border-top-color: #f5f5f5;
216
+ border-top-style: solid;
217
+ border-top-width: 1px;
218
+ }
222
219
 
223
- .uni-dialog-button {
224
- /* #ifndef APP-NVUE */
225
- display: flex;
226
- /* #endif */
220
+ .uni-dialog-button {
221
+ /* #ifndef APP-NVUE */
222
+ display: flex;
223
+ /* #endif */
227
224
 
228
- flex: 1;
229
- flex-direction: row;
230
- justify-content: center;
231
- align-items: center;
232
- height: 45px;
233
- }
225
+ flex: 1;
226
+ flex-direction: row;
227
+ justify-content: center;
228
+ align-items: center;
229
+ height: 45px;
230
+ }
234
231
 
235
- .uni-border-left {
236
- border-left-color: #f0f0f0;
237
- border-left-style: solid;
238
- border-left-width: 1px;
239
- }
232
+ .uni-border-left {
233
+ border-left-color: #f0f0f0;
234
+ border-left-style: solid;
235
+ border-left-width: 1px;
236
+ }
240
237
 
241
- .uni-dialog-button-text {
242
- font-size: 16px;
243
- color: #333;
244
- }
238
+ .uni-dialog-button-text {
239
+ font-size: 16px;
240
+ color: #333;
241
+ }
245
242
 
246
- .uni-button-color {
247
- color: #007aff;
248
- }
243
+ .uni-button-color {
244
+ color: #007aff;
245
+ }
249
246
 
250
- .uni-dialog-input {
251
- flex: 1;
252
- font-size: 14px;
253
- border: 1px #eee solid;
254
- height: 40px;
255
- padding: 0 10px;
256
- border-radius: 5px;
257
- color: #555;
258
- }
247
+ .uni-dialog-input {
248
+ flex: 1;
249
+ font-size: 14px;
250
+ border: 1px #eee solid;
251
+ height: 40px;
252
+ padding: 0 10px;
253
+ border-radius: 5px;
254
+ color: #555;
255
+ }
259
256
 
260
- .uni-popup__success {
261
- color: #4cd964;
262
- }
257
+ .uni-popup__success {
258
+ color: #4cd964;
259
+ }
263
260
 
264
- .uni-popup__warn {
265
- color: #f0ad4e;
266
- }
261
+ .uni-popup__warn {
262
+ color: #f0ad4e;
263
+ }
267
264
 
268
- .uni-popup__error {
269
- color: #dd524d;
270
- }
265
+ .uni-popup__error {
266
+ color: #dd524d;
267
+ }
271
268
 
272
- .uni-popup__info {
273
- color: #909399;
274
- }
269
+ .uni-popup__info {
270
+ color: #909399;
271
+ }
275
272
  </style>
@@ -0,0 +1 @@
1
+ export * from './kg.util';
@@ -0,0 +1,72 @@
1
+ import { isArray, isObjectLike } from 'lodash-es';
2
+ import { toRaw, unref } from 'vue';
3
+ import { useKgWarehouse } from '../component';
4
+
5
+ /**
6
+ * 通用工具.
7
+ */
8
+ export class KgUtil {
9
+ /**
10
+ * 处理请求参数.
11
+ * 1. 填充通用参数的值
12
+ * a. 仓库: '{WAREHOUSE}'
13
+ * @param params 请求参数.
14
+ */
15
+ public static parseParams(params?: Record<string, any> | null): any {
16
+ let _params = toRaw(unref(params))!;
17
+
18
+ if (!_params || !isObjectLike(_params)) {
19
+ return _params;
20
+ }
21
+
22
+ const resultParams: Record<string, any> = isArray(_params) ? [] : {};
23
+ Object.keys(_params)
24
+ .sort()
25
+ .forEach((key) => {
26
+ const value = _params[key];
27
+
28
+ switch (true) {
29
+ case isObjectLike(value):
30
+ resultParams[key] = this.parseParams(value);
31
+ break;
32
+
33
+ case typeof value === 'string':
34
+ resultParams[key] = this.parseParamFromString(value);
35
+ break;
36
+
37
+ default:
38
+ resultParams[key] = value;
39
+ break;
40
+ }
41
+ });
42
+
43
+ return resultParams;
44
+ }
45
+
46
+ /**
47
+ * 处理请求参数: 解析字符串类型的参数值.
48
+ * @param value 参数的原始值.
49
+ */
50
+ private static parseParamFromString(value: string): string {
51
+ const result: RegExpExecArray | null = /(.*)?({(.*)?})(.*)?/.exec(value);
52
+
53
+ // 若参数值包含变量, 填充这些变量
54
+ if (result) {
55
+ const placeholder = result[2];
56
+ // 去掉首尾的 {}
57
+ const key = result[2].slice(1, -1);
58
+
59
+ switch (placeholder) {
60
+ case '{WAREHOUSE}':
61
+ return value.replace('{WAREHOUSE}', useKgWarehouse().warehouse.value?.whId ?? '');
62
+
63
+ default:
64
+ break;
65
+ }
66
+
67
+ return value;
68
+ } else {
69
+ return value;
70
+ }
71
+ }
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kengic/uni",
3
- "version": "0.3.3-beta.1",
3
+ "version": "0.3.3",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build:dev": "rimraf dist && vue-tsc && vite build --mode development",
@@ -23,9 +23,6 @@
23
23
  "publish:all": "tsx scripts/publish.ts",
24
24
  "publish:npm": "npmrc kengic && npm publish ./ --registry https://registry.npmjs.org/ --access public"
25
25
  },
26
- "peerDependencies": {
27
- "vue": "3.2.47"
28
- },
29
26
  "dependencies": {
30
27
  "@ant-design/icons-vue": "6.1.0",
31
28
  "@iconify-icons/ant-design": "1.2.5",
@@ -33,7 +30,8 @@
33
30
  "@vueuse/core": "8.9.4",
34
31
  "@vueuse/shared": "8.9.4",
35
32
  "lodash-es": "4.17.21",
36
- "pinia": "2.0.35"
33
+ "pinia": "2.0.35",
34
+ "vue": "3.2.47"
37
35
  },
38
36
  "devDependencies": {
39
37
  "@dcloudio/types": "3.3.3",