@netang/quasar 0.0.42 → 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.
@@ -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.42",
3
+ "version": "0.0.43",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"