@netang/quasar 0.0.41 → 0.0.43

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.
@@ -97,9 +97,11 @@ export default {
97
97
 
98
98
  // 初始显示前置插槽
99
99
  let rawBefore = props.before
100
+ let initEmitBefore = true
100
101
 
101
102
  // 初始显示后置插槽
102
103
  let rawAfter = props.after
104
+ let initEmitAfter = true
103
105
 
104
106
  // 如果开启缓存
105
107
  if (props.cache) {
@@ -108,14 +110,15 @@ export default {
108
110
  cacheName = `splitter:${props.cache === true ? ($power && $power.routePath ? $power.routePath : utils.router.getRoute('path')) : props.cache}:`
109
111
 
110
112
  // 从缓存获取初始值
111
- let cache = utils.storage.get(cacheName + 'value')
113
+ let cache = utils.storage.get(cacheName + 'modelValue')
112
114
  if (cache !== null) {
113
115
  rawValue = cache
114
116
  }
115
117
 
116
- // 如果在手机模式
118
+ // 如果手机模式隐藏前置插槽
117
119
  if (props.hideBeforeInMobile && $q.platform.is.mobile) {
118
120
  rawBefore = false
121
+ initEmitBefore = false
119
122
 
120
123
  } else {
121
124
  // 从缓存获取初始值
@@ -125,11 +128,10 @@ export default {
125
128
  }
126
129
  }
127
130
 
128
- // 如果在手机模式
131
+ // 如果手机模式隐藏后置插槽
129
132
  if (props.hideAfterInMobile && $q.platform.is.mobile) {
130
133
  rawAfter = false
131
-
132
- console.log(777, rawAfter)
134
+ initEmitAfter = false
133
135
 
134
136
  } else {
135
137
  // 从缓存获取初始值
@@ -139,19 +141,19 @@ export default {
139
141
  }
140
142
  }
141
143
 
142
- console.log(222, rawAfter)
143
-
144
144
  // 如果在手机模式
145
145
  } else if ($q.platform.is.mobile) {
146
146
 
147
147
  // 手机模式隐藏前置插槽
148
148
  if (props.hideBeforeInMobile) {
149
149
  rawBefore = false
150
+ initEmitBefore = false
150
151
  }
151
152
 
152
- // 手机模式隐藏后插槽
153
+ // 手机模式隐藏后置插槽
153
154
  if (props.hideAfterInMobile) {
154
155
  rawAfter = false
156
+ initEmitAfter = false
155
157
  }
156
158
  }
157
159
 
@@ -160,14 +162,21 @@ export default {
160
162
 
161
163
  // 当前值
162
164
  const currentValue = ref(rawValue)
165
+ if (rawValue !== props.modelValue) {
166
+ emit('update:modelValue', rawValue)
167
+ }
163
168
 
164
169
  // 当前是否显示前置插槽
165
170
  const currentBefore = ref(rawBefore)
166
-
167
- console.log(333, rawAfter)
171
+ if (initEmitBefore) {
172
+ emit('update:before', rawBefore)
173
+ }
168
174
 
169
175
  // 当前是否显示后置插槽
170
176
  const currentAfter = ref(rawAfter)
177
+ if (initEmitAfter) {
178
+ emit('update:after', rawAfter)
179
+ }
171
180
 
172
181
  // ==========【计算属性】=========================================================================================
173
182
 
@@ -0,0 +1,243 @@
1
+ <template>
2
+ <n-splitter
3
+ class="absolute-full"
4
+ @update:after="setSelection"
5
+ :hide-after-in-mobile="hideAfterInMobile"
6
+ v-bind="$attrs"
7
+ >
8
+ <!-- 表格 -->
9
+ <template v-slot:before="{ after, toggleAfter }">
10
+ <n-table
11
+ v-bind="tableProps"
12
+ >
13
+ <!-- 工具栏右边插槽(手机端不显示) -->
14
+ <template #toolbar-right v-if="isWatcher">
15
+
16
+ <!-- 是否显示详情 -->
17
+ <q-toggle
18
+ icon="apps"
19
+ :model-value="after"
20
+ @click="toggleAfter"
21
+ >
22
+ <q-tooltip anchor="center left" self="center right" :offset="[10, 0]">{{tooltip}}</q-tooltip>
23
+ </q-toggle>
24
+
25
+ </template>
26
+
27
+ <!-- 插槽 -->
28
+ <template
29
+ v-for="slotName in slotNames"
30
+ v-slot:[slotName]="props"
31
+ >
32
+ <!-- 有传参的插槽 -->
33
+ <slot
34
+ :name="slotName"
35
+ v-bind="props"
36
+ v-if="props"
37
+ />
38
+
39
+ <!-- 无传参的插槽 -->
40
+ <slot
41
+ :name="slotName"
42
+ v-else
43
+ />
44
+ </template>
45
+
46
+ </n-table>
47
+ </template>
48
+
49
+ <!-- 渲染详情页面(手机端不显示) -->
50
+ <template v-slot:after>
51
+
52
+ <!-- 渲染 -->
53
+ <n-render
54
+ :path="path"
55
+ :query="currentQuery"
56
+ v-if="currentQuery"
57
+ />
58
+
59
+ <!-- 空状态 -->
60
+ <n-empty
61
+ :description="description"
62
+ v-else
63
+ />
64
+
65
+ </template>
66
+
67
+ </n-splitter>
68
+ </template>
69
+
70
+ <script>
71
+ import { nextTick, ref, watch, computed, inject } from 'vue'
72
+ import { useQuasar } from 'quasar'
73
+
74
+ import { NTableKey } from '../../utils/symbols'
75
+
76
+ export default {
77
+
78
+ /**
79
+ * 标识
80
+ */
81
+ name: 'NSplitterTable',
82
+
83
+ /**
84
+ * 声明属性
85
+ */
86
+ props: {
87
+ // 表格声明参数
88
+ tableProps: Object,
89
+ // 手机模式隐藏后插槽
90
+ hideAfterInMobile: {
91
+ type: Boolean,
92
+ default: true,
93
+ },
94
+ // 空状态描述
95
+ description: {
96
+ type: String,
97
+ default: '没有找到任何数据',
98
+ },
99
+ // 渲染组件路径
100
+ path: {
101
+ type: String,
102
+ required: true,
103
+ },
104
+ // 格式化已选表格的数据并返回渲染组件参数
105
+ format: Function,
106
+ // 工具提示
107
+ tooltip: {
108
+ type: String,
109
+ default: '是否显示详情',
110
+ },
111
+ },
112
+
113
+ /**
114
+ * 组合式
115
+ */
116
+ setup(props, { slots }) {
117
+
118
+ // ==========【计算属性】=========================================================================================
119
+
120
+ /**
121
+ * 插槽标识
122
+ */
123
+ const slotNames = computed(function() {
124
+ return utils.isValidObject(slots) ? Object.keys(slots) : []
125
+ })
126
+
127
+ /**
128
+ * 是否监听
129
+ */
130
+ const isWatcher = computed(function () {
131
+ return ! props.hideAfterInMobile || ! $q.platform.is.mobile
132
+ })
133
+
134
+ /**
135
+ * 当前传参
136
+ */
137
+ const currentQuery = computed(function() {
138
+
139
+ // 如果有已选数据
140
+ if (
141
+ currentSelectedItem.value
142
+ && _.isFunction(props.format)
143
+ ) {
144
+ const res = props.format(currentSelectedItem.value)
145
+ if (utils.isValidObject(res)) {
146
+
147
+ // 格式化已选数据, 并返回参数
148
+ return Object.assign({
149
+ // 是否为渲染页面
150
+ n_render_page: 1,
151
+ }, res)
152
+ }
153
+ }
154
+
155
+ return null
156
+ })
157
+
158
+ // ==========【数据】=============================================================================================
159
+
160
+ // quasar 对象
161
+ const $q = useQuasar()
162
+
163
+ // 获取表格注入
164
+ const $table = inject(NTableKey)
165
+
166
+ // 当前已选单条数据
167
+ const currentSelectedItem = ref(null)
168
+
169
+ // ==========【监听数据】=========================================================================================
170
+
171
+ /**
172
+ * 监听表格已选数据(非手机端有效)
173
+ */
174
+ watch($table.tableSelected, async function (selected) {
175
+
176
+ // 先清空当前已选单条数据
177
+ currentSelectedItem.value = null
178
+
179
+ // 如果不监听
180
+ if (! isWatcher.value) {
181
+
182
+ // 则无需任何操作
183
+ return
184
+ }
185
+
186
+ // 下次 DOM 更新
187
+ await nextTick()
188
+
189
+ // 如果有已选单条数据
190
+ if (selected.length === 1) {
191
+
192
+ // 设置当前已选数据
193
+ currentSelectedItem.value = selected[0]
194
+ }
195
+
196
+ }, {
197
+ // 深度监听
198
+ deep: true,
199
+ })
200
+
201
+ // ==========【方法】============================================================================================
202
+
203
+ /**
204
+ * 设置表格选择类型
205
+ */
206
+ function setSelection(showAfter) {
207
+
208
+ // 如果不监听
209
+ if (! isWatcher.value) {
210
+
211
+ // 则无需任何操作
212
+ return
213
+ }
214
+
215
+ const selection = showAfter ? 'single' : 'multiple'
216
+ if ($table.tableSelection.value !== selection) {
217
+ $table.tableSelection.value = selection
218
+
219
+ // 如果显示后置插槽
220
+ if (showAfter && $table.tableSelected.value.length > 1) {
221
+
222
+ // 如果有多条已选数据, 则只取第一条数据
223
+ $table.tableSelected.value = [ $table.tableSelected.value[0] ]
224
+ }
225
+ }
226
+ }
227
+
228
+ // ==========【返回】=========================================================================================
229
+
230
+ return {
231
+ // 插槽标识
232
+ slotNames,
233
+ // 是否监听
234
+ isWatcher,
235
+ // 当前传参
236
+ currentQuery,
237
+
238
+ // 设置表格选择类型
239
+ setSelection,
240
+ }
241
+ }
242
+ }
243
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"