@netang/quasar 0.1.20 → 0.1.22
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/components/editor-code/index.vue +325 -289
- package/components/field-tree/index.vue +3 -5
- package/components/private/components/move-to-tree/index.vue +154 -154
- package/components/table/index.vue +2 -2
- package/components/tree/index.vue +1636 -0
- package/package.json +1 -1
- package/utils/$form.js +6 -5
- package/utils/$power.js +2 -2
- package/utils/$tree.js +145 -202
|
@@ -1,289 +1,325 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<!-- :style="currentStyle" -->
|
|
3
|
-
<div
|
|
4
|
-
ref="targetRef"
|
|
5
|
-
:style="currentStyle"
|
|
6
|
-
></div>
|
|
7
|
-
</template>
|
|
8
|
-
|
|
9
|
-
<script>
|
|
10
|
-
import { ref, watch, computed, onMounted } from 'vue'
|
|
11
|
-
|
|
12
|
-
import script from '@netang/utils/script'
|
|
13
|
-
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
14
|
-
import $n_isValidValue from '@netang/utils/isValidValue'
|
|
15
|
-
import $n_sleep from '@netang/utils/sleep'
|
|
16
|
-
import $n_px from '@netang/utils/px'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<!-- :style="currentStyle" -->
|
|
3
|
+
<div
|
|
4
|
+
ref="targetRef"
|
|
5
|
+
:style="currentStyle"
|
|
6
|
+
></div>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import { ref, watch, computed, onMounted } from 'vue'
|
|
11
|
+
|
|
12
|
+
import script from '@netang/utils/script'
|
|
13
|
+
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
14
|
+
import $n_isValidValue from '@netang/utils/isValidValue'
|
|
15
|
+
import $n_sleep from '@netang/utils/sleep'
|
|
16
|
+
import $n_px from '@netang/utils/px'
|
|
17
|
+
|
|
18
|
+
import $n_toast from '../../utils/toast'
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 标识
|
|
24
|
+
*/
|
|
25
|
+
name: 'NEditorCode',
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 声明属性
|
|
29
|
+
*/
|
|
30
|
+
props: {
|
|
31
|
+
// 值 v-model
|
|
32
|
+
modelValue: {
|
|
33
|
+
type: [ String, Number ],
|
|
34
|
+
default: '',
|
|
35
|
+
},
|
|
36
|
+
// 原始值
|
|
37
|
+
originalValue: [ String, Number ],
|
|
38
|
+
// 宽度
|
|
39
|
+
width: {
|
|
40
|
+
type: [ String, Number ],
|
|
41
|
+
default: '100%',
|
|
42
|
+
},
|
|
43
|
+
// 高度
|
|
44
|
+
height: [ String, Number ],
|
|
45
|
+
// 脚本语言
|
|
46
|
+
language: String,
|
|
47
|
+
// 是否只读
|
|
48
|
+
readonly: Boolean,
|
|
49
|
+
// 是否显示代码视图
|
|
50
|
+
minimap: Boolean,
|
|
51
|
+
// tab 长度
|
|
52
|
+
tabSize: {
|
|
53
|
+
type: Number,
|
|
54
|
+
default: 4,
|
|
55
|
+
},
|
|
56
|
+
// 主题
|
|
57
|
+
theme: {
|
|
58
|
+
type: String,
|
|
59
|
+
default: 'vs',
|
|
60
|
+
},
|
|
61
|
+
// 是否开启差异代码
|
|
62
|
+
diff: Boolean,
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 声明事件
|
|
67
|
+
*/
|
|
68
|
+
emits: [
|
|
69
|
+
'update:modelValue',
|
|
70
|
+
],
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 组合式
|
|
74
|
+
*/
|
|
75
|
+
setup(props, { emit }) {
|
|
76
|
+
|
|
77
|
+
// ==========【计算属性】=========================================================================================
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 当前样式
|
|
81
|
+
*/
|
|
82
|
+
const currentStyle = computed(function () {
|
|
83
|
+
return {
|
|
84
|
+
width: $n_isNumeric(props.width) ? $n_px(props.width) : props.width,
|
|
85
|
+
height: $n_isNumeric(props.height) ? $n_px(props.height) : props.height,
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// ==========【数据】=============================================================================================
|
|
90
|
+
|
|
91
|
+
// 根节点
|
|
92
|
+
const targetRef = ref(null)
|
|
93
|
+
|
|
94
|
+
// 编辑器实例
|
|
95
|
+
let $editor = null
|
|
96
|
+
|
|
97
|
+
// 停止值观察
|
|
98
|
+
let stopValueWatcher = false
|
|
99
|
+
|
|
100
|
+
// 创建睡眠实例
|
|
101
|
+
const sleep = $n_sleep()
|
|
102
|
+
|
|
103
|
+
// ==========【监听数据】=========================================================================================
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 监听声明值
|
|
107
|
+
*/
|
|
108
|
+
if (! props.diff) {
|
|
109
|
+
watch(() => props.modelValue, function (val) {
|
|
110
|
+
|
|
111
|
+
// 如果停止值观察
|
|
112
|
+
if (stopValueWatcher) {
|
|
113
|
+
|
|
114
|
+
// 则无任何操作
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 取消停止值观察
|
|
119
|
+
stopValueWatcher = false
|
|
120
|
+
|
|
121
|
+
// 设置值
|
|
122
|
+
setValue(val)
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ==========【方法】============================================================================================
|
|
127
|
+
|
|
128
|
+
function load() {
|
|
129
|
+
|
|
130
|
+
// 如果已加载
|
|
131
|
+
if (window.monaco) {
|
|
132
|
+
// 创建编辑器
|
|
133
|
+
create()
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 版本
|
|
138
|
+
const version = '0.34.1'
|
|
139
|
+
|
|
140
|
+
// 加载 script
|
|
141
|
+
script([
|
|
142
|
+
[
|
|
143
|
+
`https://cdn.staticfile.org/monaco-editor/${version}/min/vs/loader.js`,
|
|
144
|
+
`https://fastly.jsdelivr.net/npm/monaco-editor@${version}/min/vs/loader.js`,
|
|
145
|
+
`https://unpkg.com/monaco-editor@${version}/min/vs/loader.js`,
|
|
146
|
+
]
|
|
147
|
+
])
|
|
148
|
+
.then(function ([ url ]) {
|
|
149
|
+
|
|
150
|
+
// 按需加载
|
|
151
|
+
const _require = window.require
|
|
152
|
+
|
|
153
|
+
// 配置
|
|
154
|
+
_require.config({
|
|
155
|
+
// 路径
|
|
156
|
+
paths: {
|
|
157
|
+
vs: url.replace('/loader.js', ''),
|
|
158
|
+
},
|
|
159
|
+
// 语言
|
|
160
|
+
'vs/nls' : {
|
|
161
|
+
availableLanguages: {
|
|
162
|
+
'*': 'zh-cn',
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
// 加载
|
|
168
|
+
_require(['vs/editor/editor.main'], function () {
|
|
169
|
+
// 创建编辑器
|
|
170
|
+
create()
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 创建编辑器
|
|
177
|
+
*/
|
|
178
|
+
function create() {
|
|
179
|
+
|
|
180
|
+
// 创建编辑器
|
|
181
|
+
$editor = monaco.editor[props.diff ? 'createDiffEditor' : 'create'](targetRef.value, {
|
|
182
|
+
// 主题
|
|
183
|
+
theme: props.theme,
|
|
184
|
+
// 脚本语言
|
|
185
|
+
language: props.language,
|
|
186
|
+
// 自动布局
|
|
187
|
+
automaticLayout: true,
|
|
188
|
+
// 自动换行
|
|
189
|
+
wordWrap: 'on',
|
|
190
|
+
// tab 长度
|
|
191
|
+
tabSize: props.tabSize,
|
|
192
|
+
// 代码略缩图
|
|
193
|
+
minimap: {
|
|
194
|
+
enabled: props.minimap,
|
|
195
|
+
},
|
|
196
|
+
// 右键
|
|
197
|
+
contextmenu: true,
|
|
198
|
+
// 是否只读
|
|
199
|
+
readOnly: props.readonly,
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
// 监听失去焦点事件
|
|
203
|
+
if (! props.diff) {
|
|
204
|
+
$editor.onDidBlurEditorText(function () {
|
|
205
|
+
|
|
206
|
+
// 获取编辑器内容
|
|
207
|
+
const value = getValue()
|
|
208
|
+
if (value === void 0) {
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 停止值观察
|
|
213
|
+
stopValueWatcher = true
|
|
214
|
+
|
|
215
|
+
// 触发更新值
|
|
216
|
+
emit('update:modelValue', value)
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 等编辑器全部加载完成后, 设置内容值
|
|
221
|
+
sleep(300)
|
|
222
|
+
.then(function () {
|
|
223
|
+
// 设置值
|
|
224
|
+
setValue(props.modelValue)
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 设置值
|
|
230
|
+
*/
|
|
231
|
+
function setValue(value) {
|
|
232
|
+
if ($editor) {
|
|
233
|
+
|
|
234
|
+
// 如果是比较差异代码
|
|
235
|
+
if (props.diff) {
|
|
236
|
+
$editor.setModel({
|
|
237
|
+
original: monaco.editor.createModel(formatValue(props.originalValue), props.language),
|
|
238
|
+
modified: monaco.editor.createModel(formatValue(value), props.language),
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
// 否则是编辑代码
|
|
242
|
+
} else {
|
|
243
|
+
// 编辑器设置内容
|
|
244
|
+
$editor.setValue(formatValue(value))
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 代码格式化
|
|
248
|
+
// $editor.getAction('editor.action.formatDocument').run()
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 获取值
|
|
254
|
+
*/
|
|
255
|
+
function getValue() {
|
|
256
|
+
|
|
257
|
+
if ($editor) {
|
|
258
|
+
|
|
259
|
+
// 获取编辑器的值
|
|
260
|
+
let value = $editor.getValue()
|
|
261
|
+
|
|
262
|
+
// 如果语言为 json
|
|
263
|
+
if (
|
|
264
|
+
props.language === 'json'
|
|
265
|
+
&& $n_isValidValue(value)
|
|
266
|
+
) {
|
|
267
|
+
try {
|
|
268
|
+
value = JSON.stringify(JSON.parse(value))
|
|
269
|
+
|
|
270
|
+
} catch (e) {
|
|
271
|
+
// 轻提示
|
|
272
|
+
$n_toast({
|
|
273
|
+
message: 'JSON 语法错误'
|
|
274
|
+
})
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return value
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return ''
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 格式化值
|
|
287
|
+
*/
|
|
288
|
+
function formatValue(value) {
|
|
289
|
+
try {
|
|
290
|
+
if (value) {
|
|
291
|
+
if (
|
|
292
|
+
props.language === 'json'
|
|
293
|
+
&& $n_isValidValue(value)
|
|
294
|
+
) {
|
|
295
|
+
return JSON.stringify(JSON.parse(value), null, 2)
|
|
296
|
+
}
|
|
297
|
+
return value
|
|
298
|
+
}
|
|
299
|
+
} catch (e) {}
|
|
300
|
+
|
|
301
|
+
return ''
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ==========【生命周期】=========================================================================================
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 实例被挂载后调用
|
|
308
|
+
*/
|
|
309
|
+
onMounted(function() {
|
|
310
|
+
|
|
311
|
+
// 加载
|
|
312
|
+
load()
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
// ==========【返回】=========================================================================================
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
// 根节点
|
|
319
|
+
targetRef,
|
|
320
|
+
// 当前样式
|
|
321
|
+
currentStyle,
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
</script>
|
|
@@ -89,10 +89,9 @@
|
|
|
89
89
|
>
|
|
90
90
|
<q-card>
|
|
91
91
|
<!-- 树 -->
|
|
92
|
-
<
|
|
93
|
-
class="q-pa-sm q-pr-md"
|
|
92
|
+
<n-tree
|
|
94
93
|
ref="treeRef"
|
|
95
|
-
style="min-width:260px;"
|
|
94
|
+
style="min-width:260px;max-height:380px;"
|
|
96
95
|
:filter="inputValue"
|
|
97
96
|
:nodes="currentTreeNodes"
|
|
98
97
|
:node-key="nodeKey"
|
|
@@ -107,14 +106,13 @@
|
|
|
107
106
|
>
|
|
108
107
|
<template v-slot:default-header="{ node }">
|
|
109
108
|
<div
|
|
110
|
-
class="cursor-pointer full-width"
|
|
111
109
|
:class="{
|
|
112
110
|
'text-primary': checkTreeNodeActive(node),
|
|
113
111
|
}"
|
|
114
112
|
@click="onNode($event, node)"
|
|
115
113
|
>{{node.label}}</div>
|
|
116
114
|
</template>
|
|
117
|
-
</
|
|
115
|
+
</n-tree>
|
|
118
116
|
|
|
119
117
|
<!-- loading -->
|
|
120
118
|
<div class="flex flex-center" style="height:100px" v-else>
|