@netang/quasar 0.0.24 → 0.0.27

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.
@@ -2,7 +2,7 @@
2
2
  <div class="flex column absolute-full" v-if="utils.isValidArray(options)">
3
3
  <q-scroll-area class="n-flex-1">
4
4
 
5
- <div class="n-search q-pa-sm q-pt-md q-gutter-md">
5
+ <div class="n-search q-pa-sm q-pt-sm q-gutter-sm">
6
6
 
7
7
  <template
8
8
  v-for="(item, itemIndex) in options"
@@ -110,13 +110,23 @@
110
110
  v-model="modelValue[itemIndex][index].value"
111
111
  dense
112
112
  outlined
113
- clearable
114
- accordion
115
113
  :multiple="multiple"
116
114
  v-bind="item.tree"
117
115
  v-else-if="item.searchType === 'tree'"
118
116
  />
119
117
 
118
+ <!-- 下拉表格 -->
119
+ <n-field-table
120
+ class="n-field-fieldset"
121
+ :label="label"
122
+ v-model="modelValue[itemIndex][index].value"
123
+ dense
124
+ outlined
125
+ :multiple="multiple"
126
+ v-bind="item.table"
127
+ v-else-if="item.searchType === 'table'"
128
+ />
129
+
120
130
  </n-search-item>
121
131
  </template>
122
132
  </template>
@@ -2,10 +2,11 @@
2
2
  <div class="n-search__item n-field-group">
3
3
 
4
4
  <!-- 比较1 -->
5
- <div class="n-field-group row">
5
+ <div class="n-field-group row no-wrap">
6
6
 
7
7
  <!-- 比较类型1 -->
8
8
  <q-select
9
+ class="n-field-group__select"
9
10
  v-model="modelValue[0].type"
10
11
  :options="compareOptions1"
11
12
  map-options
@@ -41,6 +42,7 @@
41
42
  >
42
43
  <!-- 比较类型2 -->
43
44
  <q-select
45
+ class="n-field-group__select"
44
46
  v-model="modelValue[1].type"
45
47
  :options="[
46
48
  { label: '<', value: dicts.SEARCH_TYPE__LT },
@@ -205,7 +207,12 @@ export default {
205
207
  // 第三个子节点
206
208
  &:nth-child(3) {
207
209
  .q-field__control {
210
+ height: 100% !important;
208
211
  background-color: rgba(var(--n-reverse-color-rgb), 0.04);
212
+
213
+ .q-field__marginal {
214
+ height: 100% !important;
215
+ }
209
216
  }
210
217
  }
211
218
 
@@ -1,12 +1,41 @@
1
1
  <template>
2
2
  <q-select
3
-
3
+ v-model="currentModelValue"
4
+ :options="currentOptions"
5
+ :option-label="optionLabel"
6
+ :use-input="filter"
7
+ @filter="onFilter"
8
+ v-bind="$attrs"
4
9
  >
10
+ <!-- 占位符 -->
11
+ <template v-slot:selected v-if="! currentModelValue && placeholder">
12
+ <div class="n-placeholder q-mr-xs">{{placeholder}}</div>
13
+ </template>
14
+
15
+ <!-- 插槽 -->
16
+ <template
17
+ v-for="slotName in slotNames"
18
+ v-slot:[slotName]="props"
19
+ >
20
+ <!-- 有传参的插槽 -->
21
+ <slot
22
+ :name="slotName"
23
+ v-bind="props"
24
+ v-if="props"
25
+ />
5
26
 
27
+ <!-- 无传参的插槽 -->
28
+ <slot
29
+ :name="slotName"
30
+ v-else
31
+ />
32
+ </template>
6
33
  </q-select>
7
34
  </template>
8
35
 
9
36
  <script>
37
+ import { ref, computed, watch } from 'vue'
38
+
10
39
  export default {
11
40
 
12
41
  /**
@@ -22,6 +51,19 @@ export default {
22
51
  modelValue: {
23
52
  required: true,
24
53
  },
54
+ options: {
55
+ type: Array,
56
+ default: () => []
57
+ },
58
+ // 选项标签
59
+ optionLabel: {
60
+ type: String,
61
+ default: 'label',
62
+ },
63
+ // 占位符
64
+ placeholder: String,
65
+ // 筛选
66
+ filter: Boolean,
25
67
  },
26
68
 
27
69
  /**
@@ -34,37 +76,78 @@ export default {
34
76
  /**
35
77
  * 组合式
36
78
  */
37
- setup(props, { emit }) {
79
+ setup(props, { emit, slots }) {
80
+
81
+ // ==========【计算属性】=========================================================================================
82
+
83
+ /**
84
+ * 插槽标识
85
+ */
86
+ const slotNames = computed(function() {
87
+ return utils.isValidObject(slots) ? Object.keys(slots) : []
88
+ })
38
89
 
39
90
  // ==========【当前值】===========================================================================================
40
91
 
92
+ // 当前值
93
+ const currentModelValue = ref(props.modelValue)
94
+
95
+ // 原始选项
96
+ const rawOptions = props.options
97
+
98
+ // 当前选项
99
+ const currentOptions = ref(rawOptions)
100
+
101
+ // ==========【监听数据】=========================================================================================
102
+
41
103
  /**
42
- * 原始值
104
+ * 监听声明值
43
105
  */
44
- const rawModelValue = props.modelValue
106
+ watch(()=>props.modelValue, function (val) {
107
+ // 设置当前值
108
+ currentModelValue.value = val
109
+ })
110
+
111
+ /**
112
+ * 监听当前值
113
+ */
114
+ watch(currentModelValue, function (val) {
115
+ // 更新值
116
+ emit('update:modelValue', val)
117
+ })
45
118
 
46
119
  // ==========【方法】============================================================================================
47
120
 
48
121
  /**
49
122
  * 筛选
50
123
  */
51
- function filter(value, update) {
124
+ function onFilter(value, update) {
52
125
  update(function() {
53
- // 更新值
54
- emit(
55
- 'update:modelValue',
56
- value === '' ? rawModelValue : utils.collection(rawModelValue)
57
- .where(props.optionLabel, 'like', value)
58
- .toArray()
59
- )
126
+ // 更新选项
127
+ currentOptions.value =
128
+ // 如果搜索值为空
129
+ value === '' ?
130
+ // 选项还原为初始值
131
+ rawOptions
132
+ // 否则筛选选项
133
+ : utils.collection(rawOptions)
134
+ .where(props.optionLabel, 'like', value)
135
+ .toArray()
60
136
  })
61
137
  }
62
138
 
63
139
  // ==========【返回】=============================================================================================
64
140
 
65
141
  return {
142
+ // 插槽标识
143
+ slotNames,
144
+ // 当前值
145
+ currentModelValue,
146
+ // 当前选项
147
+ currentOptions,
148
+
66
149
  // 筛选
67
- filter,
150
+ onFilter,
68
151
  }
69
152
  }
70
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.0.24",
3
+ "version": "0.0.27",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/$search.js CHANGED
@@ -194,12 +194,13 @@ async function getOptions(rawSearchOptions, format) {
194
194
  newItem.select.options = await utils.runAsync(newItem.select.options)()
195
195
  }
196
196
 
197
- // 如果有树选项
197
+ // 如果有树选项(调用的是 <n-field-tree> 组件)
198
198
  } else if (_.has(newItem, 'tree')) {
199
199
  newItem.searchType = 'tree'
200
200
  newItem.tree = Object.assign({
201
201
  nodes: [],
202
202
  accordion: true,
203
+ clearable: true,
203
204
  }, newItem.tree)
204
205
 
205
206
  // 如果节点数组是方法
@@ -208,6 +209,20 @@ async function getOptions(rawSearchOptions, format) {
208
209
  newItem.tree.nodes = await utils.runAsync(newItem.tree.nodes)()
209
210
  }
210
211
 
212
+ // 如果有表格选项(调用的是 <n-field-table> 组件)
213
+ } else if (_.has(newItem, 'table')) {
214
+ newItem.searchType = 'table'
215
+ newItem.table = Object.assign({
216
+ // 值字段(必填)
217
+ valueKey: newItem.name,
218
+ // 是否可清除
219
+ clearable: true,
220
+ // 是否开启筛选
221
+ filter: true,
222
+ }, newItem.table)
223
+
224
+ console.log('111', newItem.table)
225
+
211
226
  // 否则为输入框
212
227
  } else {
213
228
  newItem.searchType = 'input'
package/utils/$table.js CHANGED
@@ -22,8 +22,8 @@ function create(params) {
22
22
  const $q = useQuasar()
23
23
 
24
24
  // 每页显示行数选项
25
- // const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
26
- const rowsPerPageOptions = [3, 40, 50, 100, 200, 500, 1000]
25
+ const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
26
+ // const rowsPerPageOptions = [3, 40, 50, 100, 200, 500, 1000]
27
27
 
28
28
  // 获取参数
29
29
  const o = _.merge({
@@ -556,8 +556,6 @@ function create(params) {
556
556
  }
557
557
  })
558
558
 
559
- console.log('newValue', newValue)
560
-
561
559
  // 还原表格搜索数据
562
560
  tableSearchValue.value = _.cloneDeep(newValue)
563
561
 
@@ -742,29 +740,27 @@ function create(params) {
742
740
  return
743
741
  }
744
742
 
745
- // 如果选择类型为单选
746
- if (o.selection === 'single') {
747
- tableSelected.value = [ row ]
748
-
749
- // 否则为多选
750
- } else {
743
+ const opt = {}
744
+ opt[o.rowKey] = row[o.rowKey]
751
745
 
752
- const opt = {}
753
- opt[o.rowKey] = row[o.rowKey]
746
+ // 获取当前数据索引
747
+ const itemIndex = _.findIndex(tableSelected.value, opt)
754
748
 
755
- // 获取当前数据索引
756
- const itemIndex = _.findIndex(tableSelected.value, opt)
749
+ // 如果不存在, 则添加
750
+ if (itemIndex === -1) {
757
751
 
758
- // 如果不存在
759
- if (itemIndex === -1) {
760
- // 则添加
761
- tableSelected.value.push(row)
752
+ // 如果选择类型为单选
753
+ if (o.selection === 'single') {
754
+ tableSelected.value = [ row ]
762
755
 
763
- // 否则
756
+ // 否则为多选
764
757
  } else {
765
- // 删除
766
- tableSelected.value.splice(itemIndex, 1)
758
+ tableSelected.value.push(row)
767
759
  }
760
+
761
+ // 否则删除
762
+ } else {
763
+ tableSelected.value.splice(itemIndex, 1)
768
764
  }
769
765
  }
770
766
 
@@ -898,7 +894,7 @@ function create(params) {
898
894
  }
899
895
 
900
896
  /**
901
- * 获取配置
897
+ * 获取表格配置
902
898
  */
903
899
  function config(routePath, path, defaultValue) {
904
900
  return _.get(tablesConfig, utils.slash(routePath, 'start', false) + (path ? '.' + path : ''), defaultValue)
@@ -910,6 +906,6 @@ function config(routePath, path, defaultValue) {
910
906
  utils.$table = {
911
907
  // 创建表格
912
908
  create,
913
- // 获取配置
909
+ // 获取表格配置
914
910
  config,
915
911
  }
@@ -1,67 +0,0 @@
1
- /**
2
- * 删除前后字符
3
- * @param {string} value
4
- * @param {string} char
5
- * @param {RegExp} regExp
6
- * @returns {string}
7
- */
8
- function trimExtraChar(value, char, regExp) {
9
- const index = value.indexOf(char)
10
- let prefix = ''
11
-
12
- if (index === -1) {
13
- return value
14
- }
15
-
16
- if (char === '-' && index !== 0) {
17
- return value.slice(0, index)
18
- }
19
-
20
- if (char === '.' && value.match(/^(\.|-\.)/)) {
21
- prefix = index ? '-0' : '0'
22
- }
23
-
24
- return (
25
- prefix + value.slice(0, index + 1) + value.slice(index).replace(regExp, '')
26
- )
27
- }
28
-
29
- /**
30
- * 格式化数字
31
- * @param {string} value
32
- * @param {boolean} allowDot
33
- * @param {boolean} allowMinus
34
- * @returns {string}
35
- */
36
- export function formatNumbers(
37
- value,
38
- allowDot = true,
39
- allowMinus = true
40
- ) {
41
- if (allowDot) {
42
- value = trimExtraChar(value, '.', /\./g)
43
- } else {
44
- value = value.split('.')[0]
45
- }
46
-
47
- if (allowMinus) {
48
- value = trimExtraChar(value, '-', /-/g)
49
- } else {
50
- value = value.replace(/-/, '')
51
- }
52
-
53
- const regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g
54
-
55
- return value.replace(regExp, '')
56
- }
57
-
58
- /**
59
- * 增加数字
60
- * @param {number} num1
61
- * @param {number} num2
62
- * @returns {number}
63
- */
64
- export function addNumber(num1, num2) {
65
- const cardinal = 10 ** 10
66
- return Math.round((num1 + num2) * cardinal) / cardinal
67
- }
@@ -1,213 +0,0 @@
1
- <template>
2
- <q-input
3
- v-model="currentValue"
4
- @blur="onBlur"
5
- v-bind="$attrs"
6
- >
7
- <template
8
- v-for="slotName in slotNames"
9
- v-slot:[slotName]
10
- >
11
- <slot :name="slotName" />
12
- </template>
13
- </q-input>
14
- </template>
15
-
16
- <script>
17
- import { computed, ref, watch } from 'vue'
18
-
19
- /**
20
- * 金额(分转元)
21
- */
22
- export default {
23
-
24
- /**
25
- * 标识
26
- */
27
- name: 'NInputPrice',
28
-
29
- /**
30
- * 声明属性
31
- */
32
- props: {
33
- // 值
34
- modelValue: [String, Number],
35
- // 最小值(分)
36
- min: {
37
- type: Number,
38
- default: 1,
39
- },
40
- // 最大值(分)
41
- max: Number,
42
- },
43
-
44
- /**
45
- * 声明事件
46
- */
47
- emits: [
48
- 'update:modelValue',
49
- ],
50
-
51
- /**
52
- * 组合式
53
- */
54
- setup(props, { emit, slots }) {
55
-
56
- // ==========【数据】============================================================================================
57
-
58
- // 当前值
59
- const currentValue = ref(formatModelValue())
60
-
61
- // ==========【计算属性】==========================================================================================
62
-
63
- /**
64
- * 插槽标识数组
65
- */
66
- const slotNames = computed(function() {
67
- if (utils.isValidObject(slots)) {
68
- return Object.keys(slots)
69
- }
70
- return []
71
- })
72
-
73
- /**
74
- * 最大值
75
- */
76
- const maxValue = computed(function() {
77
- const maxValue = new BigNumber(props.max)
78
- if (maxValue.isFinite()) {
79
- return maxValue
80
- .dividedBy(100)
81
- .toNumber()
82
- }
83
- return null
84
- })
85
-
86
- /**
87
- * 最小值
88
- */
89
- const minValue = computed(function() {
90
- const maxValue = new BigNumber(props.min)
91
- if (maxValue.isFinite()) {
92
- return maxValue
93
- .dividedBy(100)
94
- .toNumber()
95
- }
96
- return null
97
- })
98
-
99
- // ==========【监听数据】=========================================================================================
100
-
101
- /**
102
- * 监听声明值
103
- */
104
- watch(()=>props.modelValue, function() {
105
- currentValue.value = formatModelValue()
106
- })
107
-
108
- // ==========【方法】=============================================================================================
109
-
110
- /**
111
- * 格式化传值
112
- */
113
- function formatModelValue() {
114
- // 分转元
115
- return utils.price(props.modelValue, '')
116
- }
117
-
118
- /**
119
- * 提交值
120
- */
121
- function emitModelValue(newVal) {
122
- // 更新值(元转分)
123
- emit('update:modelValue', utils.priceYuanToCent(newVal, ''))
124
- }
125
-
126
- /**
127
- * 失去焦点触发
128
- */
129
- function onBlur() {
130
-
131
- if (utils.isValidValue(currentValue.value)) {
132
-
133
- let val = new BigNumber(currentValue.value)
134
-
135
- if (val.isFinite()) {
136
-
137
- // 值是否有更新
138
- let isChange = false
139
-
140
- if (
141
- // 如果值 > 0
142
- val.isGreaterThan(0)
143
- // 如果值精度 > 2
144
- && val.decimalPlaces() > 2
145
- ) {
146
- // 值有更新
147
- isChange = true
148
-
149
- // 将元向下舍入 2 位精度(如 68.345 -> 68.34)
150
- val = val.decimalPlaces(2, BigNumber.ROUND_DOWN)
151
- }
152
-
153
- // 如果值 >= 最大值
154
- if (maxValue.value !== null) {
155
- if (val.isGreaterThanOrEqualTo(maxValue.value)) {
156
-
157
- // 更新当前值
158
- currentValue.value = maxValue.value
159
-
160
- // 提交值
161
- emitModelValue(currentValue.value)
162
- return
163
- }
164
- }
165
-
166
- // 如果值 <= 最小值
167
- if (minValue.value !== null) {
168
- if (val.isLessThanOrEqualTo(minValue.value)) {
169
-
170
- // 更新当前值
171
- currentValue.value = minValue.value
172
-
173
- // 提交值
174
- emitModelValue(currentValue.value)
175
- return
176
- }
177
- }
178
-
179
- // 获取最新值
180
- val = val.toNumber()
181
-
182
- if (isChange) {
183
- // 更新当前值
184
- currentValue.value = val
185
- }
186
-
187
- // 提交值
188
- emitModelValue(val)
189
- return
190
- }
191
- }
192
-
193
- // 更新当前值
194
- currentValue.value = ''
195
-
196
- // 提交值
197
- emitModelValue(currentValue.value)
198
- }
199
-
200
- // ==========【返回】=============================================================================================
201
-
202
- return {
203
- // 当前值
204
- currentValue,
205
- // 插槽标识数组
206
- slotNames,
207
-
208
- // 失去焦点触发
209
- onBlur,
210
- }
211
- },
212
- }
213
- </script>