@netang/quasar 0.1.32 → 0.1.34

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.
Files changed (224) hide show
  1. package/.editorconfig +12 -12
  2. package/_docs/docs/components/field-table.md +58 -58
  3. package/_docs/docs/components/field-tree.md +21 -21
  4. package/_docs/docs/components/table.md +24 -24
  5. package/_docs/docs/utils/table.md +196 -196
  6. package/components/editor-code/index.vue +325 -325
  7. package/components/field-table/index.vue +1227 -1227
  8. package/components/field-tree/index.vue +757 -757
  9. package/components/mixed-table/index.vue +473 -473
  10. package/components/mixed-table-splitter/index.vue +377 -377
  11. package/components/private/components/move-to-tree/index.vue +154 -154
  12. package/components/private/edit-power-data/index.vue +846 -846
  13. package/components/private/table-visible-columns-button/index.vue +109 -109
  14. package/components/render/index.vue +127 -127
  15. package/components/search/index.vue +224 -224
  16. package/components/search-item/index.vue +212 -212
  17. package/components/select/index.vue +177 -177
  18. package/components/table/index.vue +513 -513
  19. package/components/table-column-fixed/index.vue +110 -110
  20. package/components/table-summary/index.vue +107 -107
  21. package/components/tree/index.vue +22 -4
  22. package/docs/404.html +33 -33
  23. package/docs/assets/404.html-60b35caa.js +1 -1
  24. package/docs/assets/404.html-d1e63d77.js +1 -1
  25. package/docs/assets/alert.html-b2a2a72f.js +5 -5
  26. package/docs/assets/alert.html-ba46d137.js +1 -1
  27. package/docs/assets/app-9f30aa4b.js +6 -6
  28. package/docs/assets/area.html-01b9b58d.js +42 -42
  29. package/docs/assets/area.html-9a4fce6a.js +1 -1
  30. package/docs/assets/arr.html-145d27e7.js +1 -1
  31. package/docs/assets/arr.html-674e65ab.js +11 -11
  32. package/docs/assets/auth.html-579fa830.js +1 -1
  33. package/docs/assets/auth.html-8544ed95.js +8 -8
  34. package/docs/assets/bus.html-c71254aa.js +1 -1
  35. package/docs/assets/bus.html-dc7d3d19.js +6 -6
  36. package/docs/assets/column-title.html-c735cb5a.js +3 -3
  37. package/docs/assets/column-title.html-e9316762.js +1 -1
  38. package/docs/assets/confirm.html-ddfdc27f.js +10 -10
  39. package/docs/assets/confirm.html-ef3e2bef.js +1 -1
  40. package/docs/assets/copy.html-d20345b6.js +1 -1
  41. package/docs/assets/copy.html-ef8c8571.js +13 -13
  42. package/docs/assets/data.html-6432175d.js +30 -30
  43. package/docs/assets/data.html-a3b05d5b.js +1 -1
  44. package/docs/assets/dialog.html-1f698e5a.js +1 -1
  45. package/docs/assets/dialog.html-62902b83.js +68 -68
  46. package/docs/assets/dialog.html-baea77c9.js +1 -1
  47. package/docs/assets/dialog.html-bb082fc4.js +1 -1
  48. package/docs/assets/dict.html-1311da3d.js +23 -23
  49. package/docs/assets/dict.html-b96fbf0c.js +1 -1
  50. package/docs/assets/dictOptions.html-7c4f40a5.js +1 -1
  51. package/docs/assets/dictOptions.html-fb99d175.js +5 -5
  52. package/docs/assets/dragger.html-668d3efa.js +1 -1
  53. package/docs/assets/dragger.html-749d585a.js +1 -1
  54. package/docs/assets/editor-code.html-6ab26ea9.js +1 -1
  55. package/docs/assets/editor-code.html-d196205d.js +1 -1
  56. package/docs/assets/empty.html-1c139131.js +1 -1
  57. package/docs/assets/empty.html-1e9c441d.js +1 -1
  58. package/docs/assets/field-date.html-069fdb13.js +1 -1
  59. package/docs/assets/field-date.html-ad204aa9.js +1 -1
  60. package/docs/assets/field-table.html-ce480f03.js +1 -1
  61. package/docs/assets/field-table.html-d9236160.js +1 -1
  62. package/docs/assets/field-text.html-7277c62f.js +1 -1
  63. package/docs/assets/field-text.html-ccb4cecf.js +1 -1
  64. package/docs/assets/field-tree.html-519bfb45.js +1 -1
  65. package/docs/assets/field-tree.html-fdc748d6.js +1 -1
  66. package/docs/assets/form.html-2b562c37.js +2 -2
  67. package/docs/assets/form.html-75104cd5.js +1 -1
  68. package/docs/assets/framework-204010b2.js +5 -5
  69. package/docs/assets/getData.html-990e3787.js +1 -1
  70. package/docs/assets/getData.html-bb72025f.js +34 -34
  71. package/docs/assets/getFile.html-42368004.js +1 -1
  72. package/docs/assets/getFile.html-99abd054.js +3 -3
  73. package/docs/assets/getImage.html-3429c5a1.js +1 -1
  74. package/docs/assets/getImage.html-4d886d83.js +3 -3
  75. package/docs/assets/getTime.html-7435f922.js +1 -1
  76. package/docs/assets/getTime.html-b37f49eb.js +20 -20
  77. package/docs/assets/img.html-7d1da657.js +1 -1
  78. package/docs/assets/img.html-fbea1105.js +1 -1
  79. package/docs/assets/index.html-1695dd7c.js +1 -1
  80. package/docs/assets/index.html-65a4aa67.js +1 -1
  81. package/docs/assets/index.html-7b98d5bd.js +1 -1
  82. package/docs/assets/index.html-c01f2648.js +1 -1
  83. package/docs/assets/input-number.html-0b250d2a.js +1 -1
  84. package/docs/assets/input-number.html-a8eb0378.js +1 -1
  85. package/docs/assets/list-menu-item.html-7f1b4611.js +1 -1
  86. package/docs/assets/list-menu-item.html-84ed5ab8.js +1 -1
  87. package/docs/assets/list-menu.html-28b4163f.js +1 -1
  88. package/docs/assets/list-menu.html-cb6ba95b.js +1 -1
  89. package/docs/assets/loading.html-dae9e39d.js +6 -6
  90. package/docs/assets/loading.html-dc74c9e6.js +1 -1
  91. package/docs/assets/notify.html-e6c4c514.js +1 -1
  92. package/docs/assets/notify.html-f2c4d914.js +8 -8
  93. package/docs/assets/power-page.html-32e02f82.js +1 -1
  94. package/docs/assets/power-page.html-485e77da.js +1 -1
  95. package/docs/assets/power.html-d258cc19.js +93 -93
  96. package/docs/assets/power.html-e490bd32.js +1 -1
  97. package/docs/assets/previewImage.html-6a6b4245.js +1 -1
  98. package/docs/assets/previewImage.html-c5b7e945.js +2 -2
  99. package/docs/assets/price.html-1882c548.js +19 -19
  100. package/docs/assets/price.html-94d3f5be.js +1 -1
  101. package/docs/assets/price.html-d213df0f.js +1 -1
  102. package/docs/assets/price.html-deaf880f.js +1 -1
  103. package/docs/assets/render.html-8efcbdd4.js +1 -1
  104. package/docs/assets/render.html-df228e38.js +1 -1
  105. package/docs/assets/rule.html-2cd57fc2.js +13 -13
  106. package/docs/assets/rule.html-61662001.js +1 -1
  107. package/docs/assets/ruleValid.html-04fe2552.js +1 -1
  108. package/docs/assets/ruleValid.html-e0a776af.js +14 -14
  109. package/docs/assets/search-0782d0d1.svg +1 -1
  110. package/docs/assets/search-item.html-3f75394c.js +1 -1
  111. package/docs/assets/search-item.html-4e942ecd.js +1 -1
  112. package/docs/assets/search.html-2807043e.js +1 -1
  113. package/docs/assets/search.html-c24f8806.js +1 -1
  114. package/docs/assets/select.html-00d0607c.js +1 -1
  115. package/docs/assets/select.html-de7731f5.js +1 -1
  116. package/docs/assets/splitter.html-56f51a70.js +1 -1
  117. package/docs/assets/splitter.html-f5c836d7.js +1 -1
  118. package/docs/assets/style-161e43ab.css +1 -1
  119. package/docs/assets/symbols.html-a6aea4bf.js +1 -1
  120. package/docs/assets/symbols.html-b1f65bad.js +21 -21
  121. package/docs/assets/table-column-fixed.html-3a69e7b2.js +1 -1
  122. package/docs/assets/table-column-fixed.html-e763c38b.js +1 -1
  123. package/docs/assets/table-pagination.html-236934d3.js +1 -1
  124. package/docs/assets/table-pagination.html-c37ee2ac.js +1 -1
  125. package/docs/assets/table-splitter.html-07eab15c.js +1 -1
  126. package/docs/assets/table-splitter.html-7670ee65.js +1 -1
  127. package/docs/assets/table-summary.html-04db434f.js +1 -1
  128. package/docs/assets/table-summary.html-943c65a0.js +1 -1
  129. package/docs/assets/table.html-36253ad7.js +1 -1
  130. package/docs/assets/table.html-7f9c5d1b.js +38 -38
  131. package/docs/assets/table.html-93d53dc8.js +1 -1
  132. package/docs/assets/table.html-ac99b9cb.js +1 -1
  133. package/docs/assets/thumbnail.html-bab1976b.js +1 -1
  134. package/docs/assets/thumbnail.html-eb64e5e8.js +1 -1
  135. package/docs/assets/timestamp.html-4e54f79b.js +13 -13
  136. package/docs/assets/timestamp.html-d0e1b88a.js +1 -1
  137. package/docs/assets/toast.html-58ecbe21.js +1 -1
  138. package/docs/assets/toast.html-c9b9d36b.js +6 -6
  139. package/docs/assets/toolbar.html-83d9f97c.js +1 -1
  140. package/docs/assets/toolbar.html-ff7b8c92.js +1 -1
  141. package/docs/assets/tree.html-d07cbe79.js +23 -23
  142. package/docs/assets/tree.html-ea04193e.js +1 -1
  143. package/docs/assets/uploader-query.html-05590718.js +1 -1
  144. package/docs/assets/uploader-query.html-3175bac5.js +1 -1
  145. package/docs/assets/uploader.html-36da4394.js +2 -2
  146. package/docs/assets/uploader.html-6b5f3079.js +1 -1
  147. package/docs/assets/uploader.html-b9340b57.js +1 -1
  148. package/docs/assets/uploader.html-bc1c22e3.js +1 -1
  149. package/docs/assets/value-format.html-8ae3d47d.js +1 -1
  150. package/docs/assets/value-format.html-afa99b3d.js +1 -1
  151. package/docs/components/column-title.html +35 -35
  152. package/docs/components/data.html +62 -62
  153. package/docs/components/dialog.html +33 -33
  154. package/docs/components/dragger.html +33 -33
  155. package/docs/components/editor-code.html +33 -33
  156. package/docs/components/empty.html +33 -33
  157. package/docs/components/field-date.html +33 -33
  158. package/docs/components/field-table.html +33 -33
  159. package/docs/components/field-text.html +33 -33
  160. package/docs/components/field-tree.html +33 -33
  161. package/docs/components/img.html +33 -33
  162. package/docs/components/input-number.html +33 -33
  163. package/docs/components/list-menu-item.html +33 -33
  164. package/docs/components/list-menu.html +33 -33
  165. package/docs/components/power-page.html +33 -33
  166. package/docs/components/price.html +33 -33
  167. package/docs/components/render.html +33 -33
  168. package/docs/components/search-item.html +33 -33
  169. package/docs/components/search.html +33 -33
  170. package/docs/components/select.html +33 -33
  171. package/docs/components/splitter.html +33 -33
  172. package/docs/components/table-column-fixed.html +33 -33
  173. package/docs/components/table-pagination.html +33 -33
  174. package/docs/components/table-splitter.html +33 -33
  175. package/docs/components/table-summary.html +33 -33
  176. package/docs/components/table.html +33 -33
  177. package/docs/components/thumbnail.html +33 -33
  178. package/docs/components/toolbar.html +33 -33
  179. package/docs/components/uploader-query.html +33 -33
  180. package/docs/components/uploader.html +33 -33
  181. package/docs/components/value-format.html +33 -33
  182. package/docs/index.html +33 -33
  183. package/docs/utils/alert.html +37 -37
  184. package/docs/utils/area.html +74 -74
  185. package/docs/utils/arr.html +43 -43
  186. package/docs/utils/auth.html +40 -40
  187. package/docs/utils/bus.html +38 -38
  188. package/docs/utils/confirm.html +42 -42
  189. package/docs/utils/copy.html +45 -45
  190. package/docs/utils/dialog.html +100 -100
  191. package/docs/utils/dict.html +55 -55
  192. package/docs/utils/dictOptions.html +37 -37
  193. package/docs/utils/form.html +34 -34
  194. package/docs/utils/getData.html +66 -66
  195. package/docs/utils/getFile.html +35 -35
  196. package/docs/utils/getImage.html +35 -35
  197. package/docs/utils/getTime.html +52 -52
  198. package/docs/utils/index.html +33 -33
  199. package/docs/utils/loading.html +38 -38
  200. package/docs/utils/notify.html +40 -40
  201. package/docs/utils/power.html +125 -125
  202. package/docs/utils/previewImage.html +34 -34
  203. package/docs/utils/price.html +51 -51
  204. package/docs/utils/rule.html +45 -45
  205. package/docs/utils/ruleValid.html +46 -46
  206. package/docs/utils/symbols.html +53 -53
  207. package/docs/utils/table.html +70 -70
  208. package/docs/utils/timestamp.html +45 -45
  209. package/docs/utils/toast.html +38 -38
  210. package/docs/utils/tree.html +55 -55
  211. package/docs/utils/uploader.html +34 -34
  212. package/package.json +1 -1
  213. package/sass/common.scss +179 -179
  214. package/sass/quasar/field.scss +250 -250
  215. package/sass/quasar/table.scss +161 -161
  216. package/sass/variables.scss +138 -138
  217. package/utils/$form.js +72 -72
  218. package/utils/$power.js +1233 -1233
  219. package/utils/$render.js +75 -75
  220. package/utils/$table.js +1171 -1171
  221. package/utils/$tree.js +664 -664
  222. package/utils/index.js +62 -62
  223. package/utils/timestamp.js +18 -18
  224. package/utils/useSearch.js +496 -496
package/utils/$table.js CHANGED
@@ -1,1171 +1,1171 @@
1
- import { ref, computed, provide, inject, watch } from 'vue'
2
- import { useQuasar } from 'quasar'
3
-
4
- import $n_has from 'lodash/has'
5
- import $n_get from 'lodash/get'
6
- import $n_cloneDeep from 'lodash/cloneDeep'
7
- import $n_merge from 'lodash/merge'
8
- import $n_isFunction from 'lodash/isFunction'
9
- import $n_findIndex from 'lodash/findIndex'
10
- import $n_uniq from 'lodash/uniq'
11
- import $n_concat from 'lodash/concat'
12
- import $n_isNil from 'lodash/isNil'
13
-
14
- import $n_router from '@netang/utils/vue/router'
15
-
16
- import $n_forEach from '@netang/utils/forEach'
17
- import $n_isValidArray from '@netang/utils/isValidArray'
18
- import $n_isValidString from '@netang/utils/isValidString'
19
- import $n_indexOf from '@netang/utils/indexOf'
20
- import $n_storage from '@netang/utils/storage'
21
-
22
- import $n_isRequired from '@netang/utils/isRequired'
23
- import $n_forIn from '@netang/utils/forIn'
24
- import $n_runAsync from '@netang/utils/runAsync'
25
- import $n_isValidObject from '@netang/utils/isValidObject'
26
- import $n_isValidValue from '@netang/utils/isValidValue'
27
- import $n_slash from '@netang/utils/slash'
28
- import $n_http from '@netang/utils/http'
29
-
30
- import $n_$power from './$power'
31
- import $n_dict from './dict'
32
- import $n_price from './price'
33
- import $n_getTime from './getTime'
34
-
35
- import { configs } from './config'
36
-
37
- import {
38
- // 设置单个搜索值
39
- setItemValue,
40
- // 从表格列获取原始值
41
- getRawData,
42
- // 获取参数
43
- getOptions,
44
- // 格式化值
45
- formatValue,
46
- } from './useSearch'
47
-
48
- import { NRenderKey, NPowerKey, NTableKey } from './symbols'
49
-
50
- const {
51
- // 表格配置
52
- tablesConfig,
53
- } = configs
54
-
55
- /**
56
- * 创建表格
57
- */
58
- function create(options) {
59
-
60
- // ==========【数据】=================================================================================================
61
-
62
- // quasar 对象
63
- const $q = useQuasar()
64
-
65
- // 每页显示行数选项
66
- const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
67
-
68
- // 原始参数
69
- const rawOptions = {
70
- // 路由路径
71
- path: '',
72
- // 请求地址(默认为 path)
73
- url: '',
74
- // 路由参数
75
- query: {},
76
- // 附加请求数据
77
- data: {},
78
- // 表格行唯一键值
79
- rowKey: 'id',
80
- // 选择类型, 可选值 none single(默认) multiple
81
- // selection: '',
82
- // 分隔栏, 可选值 horizontal vertical cell none
83
- separator: 'cell',
84
- // 初始已选数据
85
- selected: [],
86
- // 初始表格加载状态
87
- loading: false,
88
- // 表格列数据(对象数组)
89
- columns: [],
90
- // 初始可见列
91
- visibleColumns: [],
92
- // 表格行数据
93
- rows: [],
94
- // 表格翻页参数
95
- pagination: {
96
- // 页码
97
- page: 1,
98
- // 每页的数据条数
99
- rowsPerPage: $n_has(options, 'rowsPerPageOptions') ? options.rowsPerPageOptions[0] : rowsPerPageOptions[0],
100
- // 数据总数(服务器返回)
101
- rowsNumber: 1,
102
- // 排序字段
103
- sortBy: null,
104
- // sortBy: 'id',
105
- // 是否降序排列
106
- descending: true,
107
- },
108
- // 每页显示行数选项
109
- rowsPerPageOptions,
110
- // 自定义请求方法
111
- request: null,
112
- // 格式化单条数据
113
- formatRow: null,
114
- // http 设置
115
- httpSettings: {},
116
- // 是否开启初始搜素
117
- search: true,
118
- // 是否开启合计
119
- summary: false,
120
- // 从参数中获取搜索值
121
- searchFromQuery: true,
122
- // 是否显示宫格
123
- showGrid: true,
124
- // 是否显示可见列
125
- showVisibleColumns: true,
126
- // 是否开启缓存
127
- cache: true,
128
- // 是否刷新后清空已选数据
129
- refreshResetSelected: true,
130
-
131
- // 单击表格行事件
132
- rowClick: null,
133
- // 双击表格行事件
134
- rowDblClick: null,
135
- }
136
-
137
- let o
138
- let $power
139
- let hasPowr
140
- let $render
141
- let $route
142
- let hasPowerBtns
143
- let tableSelected
144
- let isCache
145
- let cacheName
146
- let tableColumns
147
- let tableImgNames
148
-
149
- // 获取可见列缓存
150
- let visibleColumnsCache
151
- // 表格可见列
152
- let tableVisibleColumns
153
- // 表格加载状态
154
- let tableLoading
155
- // 表格行数据
156
- let tableRows
157
- // 表格翻页参数
158
- let tablePagination
159
- // 表格宫格
160
- let tableGrid
161
- // 表格请求参数(将表格传参中的搜索参数剥离掉, 剩下的直接当做参数传递给服务器)
162
- let tableRequestQuery
163
- // 是否请求表格合计
164
- let isRequestSummary
165
- // 表格合计
166
- let tableSummary
167
- // 表格选择类型
168
- let tableSelection
169
- // 表格分隔栏
170
- let tableSeparator
171
-
172
- // 原始参数
173
- let rawQuery
174
- // 原始表格搜索参数
175
- let rawSearchOptions
176
- // 原始表格搜索值(空表格搜索值, 用于搜索重置)
177
- let rawTableSearchValue
178
- // 首次表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
179
- let firstTableSearchValue
180
-
181
- // 表格搜索数据值
182
- let tableSearchValue
183
- // 表格搜索参数
184
- let tableSearchOptions
185
- // 是否已加载
186
- let _isTableLoaded
187
-
188
- // 是否已生成数据
189
- let _isCreated = false
190
-
191
- // 创建表格
192
- reCreate(options)
193
-
194
- // 已生成数据
195
- _isCreated = true
196
-
197
- // ==========【方法】================================================================================================
198
-
199
- /**
200
- * 重新创建表格
201
- */
202
- function reCreate(options) {
203
-
204
- // 获取参数
205
- o = $n_merge({}, rawOptions, options)
206
-
207
- // 获取权限注入
208
- $power = $n_has(options, '$power') ? options.$power : (_isCreated ? $power : inject(NPowerKey))
209
- hasPowr = !! $power
210
-
211
- // 获取渲染注入
212
- $render = $n_has(options, '$render') ? options.$render : (_isCreated ? $render : inject(NRenderKey))
213
- if (!! $render) {
214
- // 如果有表格传参, 则合并参数
215
- const tableProps = $n_get($render, 'props.tableProps')
216
- if ($n_isValidObject(tableProps)) {
217
- $n_merge(o, tableProps)
218
- }
219
- }
220
-
221
- // 获取选择类型(默认 single)
222
- if (! $n_has(o, 'selection') || ! $n_isValidString(o.selection)) {
223
- if (hasPowr) {
224
- o.selection = $n_get($power, 'powerPage.data.selection')
225
- if (! $n_isValidString(o.selection)) {
226
- o.selection = 'single'
227
- }
228
- } else {
229
- o.selection = 'single'
230
- }
231
- }
232
-
233
- // 获取权限路由
234
- $route = $n_isValidString(o.path) ?
235
- // 如果为自定义路由
236
- $n_router.resolve({
237
- path: o.path,
238
- query: $n_isValidObject(o.query) ? o.query : {},
239
- })
240
- // 否则获取当前路由
241
- : (hasPowr ? $power.getRoute() : $n_router.getRoute())
242
-
243
- // 是否有权限按钮
244
- const _hasPowerBtns = hasPowr ? $power.powerBtns.value.length : false
245
- if (_isCreated) {
246
- hasPowerBtns.value = _hasPowerBtns
247
- } else {
248
- hasPowerBtns = ref(_hasPowerBtns)
249
- }
250
-
251
- // 表格已选数据
252
- if (hasPowr) {
253
- tableSelected = $power.tableSelected
254
- } else if (_isCreated) {
255
- tableSelected.value = []
256
- } else {
257
- tableSelected = ref([])
258
- }
259
- if ($n_isValidArray(o.selected)) {
260
- tableSelected.value = o.selected
261
- }
262
-
263
- // 是否开启缓存
264
- isCache = !! o.cache
265
-
266
- // 缓存名
267
- cacheName = $route.path ? $route.path : ($n_isValidString(o.cache) ? o.cache : '')
268
-
269
- // 表格列
270
- const _tableColumns = []
271
-
272
- // 如果有权限按钮
273
- if (hasPowerBtns.value) {
274
- // 添加操作列
275
- o.columns.push({
276
- label: '操作',
277
- name: 'settings',
278
- })
279
- }
280
-
281
- // 表格图片标识数组
282
- if (_isCreated) {
283
- tableImgNames.value = []
284
- } else {
285
- tableImgNames = ref([])
286
- }
287
-
288
- // 设置表格列数据
289
- // 设置列参数
290
- $n_forEach(o.columns, function(item) {
291
-
292
- if (
293
- ! $n_has(item, 'field')
294
- && $n_has(item, 'name')
295
- ) {
296
- item.field = item.name
297
- }
298
-
299
- if (! $n_has(item, 'align')) {
300
- item.align = 'left'
301
- }
302
-
303
- // 是否隐藏
304
- item.hide = $n_get(item, 'hide') === true
305
-
306
- // 如果有显示项
307
- if ($n_get(item, 'visible') !== false) {
308
- o.visibleColumns.push(item.field)
309
- }
310
-
311
- // 如果有时间戳
312
- if ($n_has(item, 'time')) {
313
- item.format = val => $n_getTime(val, { format: item.time === true ? `YYYY-MM-DD HH:mm` : item.time }, '-')
314
-
315
- // 如果有数据字典
316
- } else if ($n_has(item, 'dict')) {
317
- item.format = val => $n_dict(item.dict, val)
318
-
319
- // 如果有图片
320
- } else if ($n_has(item, 'img') && item.img === true) {
321
- tableImgNames.value.push(item.name)
322
-
323
- // 如果有价格
324
- } else if ($n_has(item, 'price')) {
325
- item.format = val => $n_price(val)
326
- }
327
-
328
- // 如果有路由
329
- if ($n_get(item, 'route')) {
330
- // 如果该值在当前路由路径中, 则显示
331
- if ($n_indexOf($route.fullPath, item.route) > -1) {
332
- _tableColumns.push(item)
333
- }
334
-
335
- } else {
336
- _tableColumns.push(item)
337
- }
338
- })
339
-
340
- // 获取可见列缓存
341
- visibleColumnsCache = o.showVisibleColumns && isCache ? $n_storage.get('table:visible_columns:' + cacheName) : []
342
-
343
- // 表格可见列
344
- const _tableVisibleColumns = Array.isArray(visibleColumnsCache) ? visibleColumnsCache : $n_uniq([...o.visibleColumns])
345
-
346
- // 表格翻页参数
347
- const _tablePagination = $route.fullPath ? o.pagination : {}
348
-
349
- // 表格宫格
350
- const _tableGrid = o.showGrid && isCache ? $n_storage.get('table:grid:' + cacheName) === true : false
351
-
352
- // 获取原始数据
353
- const r = getRawData(_tableColumns, Object.assign({}, $route.query), o.searchFromQuery)
354
- // 原始参数
355
- rawQuery = r.rawQuery
356
- // 原始表格搜索参数
357
- rawSearchOptions = r.rawSearchOptions
358
- // 原始表格搜索值(空表格搜索值, 用于搜索重置)
359
- rawTableSearchValue = r.rawTableSearchValue
360
- // 首次表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
361
- firstTableSearchValue = r.firstTableSearchValue
362
-
363
- // 表格搜索数据值
364
- const _tableSearchValue = $route.fullPath ? firstTableSearchValue : []
365
-
366
- if (_isCreated) {
367
-
368
- // 表格列
369
- tableColumns.value = _tableColumns
370
-
371
- // 表格可见列
372
- tableVisibleColumns.value = _tableVisibleColumns
373
-
374
- // 表格加载状态
375
- tableLoading.value = o.loading
376
-
377
- // 表格行数据
378
- tableRows.value = o.rows
379
-
380
- // 表格翻页参数
381
- tablePagination.value = _tablePagination
382
-
383
- // 表格宫格
384
- tableGrid.value = _tableGrid
385
-
386
- // 表格合计
387
- tableSummary.value = null
388
-
389
- // 表格选择类型
390
- tableSelection.value = o.selection
391
-
392
- // 表格分隔栏
393
- tableSeparator.value = o.separator
394
-
395
- // 表格搜索数据值
396
- tableSearchValue.value = _tableSearchValue
397
-
398
- // 表格搜索参数
399
- tableSearchOptions.value = null
400
-
401
- } else {
402
-
403
- // 表格列
404
- tableColumns = ref(_tableColumns)
405
-
406
- // 表格可见列
407
- tableVisibleColumns = ref(_tableVisibleColumns)
408
-
409
- // 表格加载状态
410
- tableLoading = ref(o.loading)
411
-
412
- // 表格行数据
413
- tableRows = ref(o.rows)
414
-
415
- // 表格翻页参数
416
- tablePagination = ref(_tablePagination)
417
-
418
- // 表格宫格
419
- tableGrid = ref(_tableGrid)
420
-
421
- // 表格合计
422
- tableSummary = ref(null)
423
-
424
- // 表格选择类型
425
- tableSelection = ref(o.selection)
426
-
427
- // 表格分隔栏
428
- tableSeparator = ref(o.separator)
429
-
430
- // 表格搜索数据值
431
- tableSearchValue = ref(_tableSearchValue)
432
-
433
- // 表格搜索参数
434
- tableSearchOptions = ref(null)
435
- }
436
-
437
- // 表格请求参数(将表格传参中的搜索参数剥离掉, 剩下的直接当做参数传递给服务器)
438
- tableRequestQuery = {}
439
-
440
- // 是否请求表格合计
441
- isRequestSummary = false
442
-
443
- // 是否已加载
444
- _isTableLoaded = false
445
-
446
- // 如果开启搜索
447
- if (o.search) {
448
- // 设置表格搜索参数
449
- setTableSearchOptions()
450
- .finally()
451
- }
452
-
453
- if (_isCreated) {
454
-
455
- // 重新赋值
456
- Object.assign(resTable, {
457
- // 当前路由全路径
458
- routeFullPath: $route.fullPath,
459
- // 当前路由路径
460
- routePath: $route.path,
461
- // 当前路由参数
462
- routeQuery: $route.query,
463
- // 表格行唯一键值
464
- tableRowKey: o.rowKey,
465
- // 表格每页显示行数选项
466
- tableRowsPerPageOptions: o.rowsPerPageOptions,
467
- })
468
-
469
- if (hasPowr) {
470
- $power.update(function(data, _data) {
471
- _data.$table = resTable
472
- })
473
- }
474
- }
475
- }
476
-
477
- // ==========【计算属性】=============================================================================================
478
-
479
- /**
480
- * 固定在表格右边的权限按钮列表
481
- */
482
- const tableFixedPowerBtns = computed(function () {
483
-
484
- const lists = []
485
-
486
- if (hasPowerBtns.value) {
487
-
488
- // 先格式化权限按钮列表
489
- $n_forEach($n_$power.formatBtns($power.powerBtns.value), function(item) {
490
- // 如果是固定按钮
491
- if (item.fixed) {
492
- lists.push(item)
493
- }
494
- })
495
- }
496
-
497
- return lists
498
- })
499
-
500
- /**
501
- * 获取权限按钮中可双击的按钮
502
- */
503
- const tableDbClickPowerBtn = computed(function () {
504
- if (
505
- // 如果有权限按钮
506
- hasPowerBtns.value
507
- // 非手机模式
508
- && ! $q.platform.is.mobile
509
- // 有权限列表
510
- && $n_isValidArray($power.powerBtns.value)
511
- ) {
512
- for (const item of $power.powerBtns.value) {
513
- if ($n_has(item, 'data.dbclick') === true) {
514
- return item
515
- }
516
- }
517
- }
518
- })
519
-
520
- /**
521
- * 是否显示固定在右边的权限按钮列表
522
- */
523
- const showTableFixed = computed(function () {
524
- return $n_indexOf(tableVisibleColumns.value, 'settings') > -1
525
- })
526
-
527
- // ==========【监听数据】=============================================================================================
528
-
529
- // #if ! IS_DEV
530
-
531
- /**
532
- * 监听表格宫格模式
533
- */
534
- watch(tableGrid, function(val) {
535
- if (o.showGrid && isCache) {
536
- // 设置宫格模式缓存(永久缓存)
537
- $n_storage.set('table:grid:' + cacheName, val, 0)
538
- }
539
- })
540
-
541
- /**
542
- * 监听表格可见列
543
- */
544
- watch(tableVisibleColumns, function(val) {
545
- if (o.showVisibleColumns && isCache) {
546
- // 设置监听表格可见列缓存(永久缓存)
547
- $n_storage.set('table:visible_columns:' + cacheName, val, 0)
548
- }
549
- })
550
-
551
- // #endif
552
-
553
- /**
554
- * 监听固定在右边的权限按钮列表
555
- */
556
- watch(tableFixedPowerBtns, function (lists) {
557
-
558
- if (! hasPowerBtns.value) {
559
- return
560
- }
561
-
562
- const index = $n_indexOf(tableVisibleColumns.value, 'settings')
563
-
564
- // 如果有固定在右边的权限按钮列表
565
- if ($n_isValidArray(lists)) {
566
-
567
- // 如果设置不在可见列中
568
- if (index === -1) {
569
-
570
- // 如果非手机模式
571
- if (! $q.platform.is.mobile) {
572
-
573
- // 则将设置加入可见列中
574
- tableVisibleColumns.value.push('settings')
575
- }
576
-
577
- // 否则在可见列中 && 如果是手机模式
578
- } else if ($q.platform.is.mobile) {
579
-
580
- // 则将设置从可见列中删除
581
- tableVisibleColumns.value.splice(index, 1)
582
- }
583
-
584
- // 否则如果设置在可见列中
585
- } else if (index > -1) {
586
-
587
- // 则将设置从可见列中删除
588
- tableVisibleColumns.value.splice(index, 1)
589
- }
590
-
591
- }, {
592
- // 立即执行
593
- immediate: true,
594
- })
595
-
596
- // ==========【方法】================================================================================================
597
-
598
- /**
599
- * 设置表格传参
600
- */
601
- function setQuery(query) {
602
-
603
- if ($n_isValidObject(query)) {
604
-
605
- query = $n_cloneDeep(query)
606
-
607
- // 搜索参数键值数组
608
- const searchQueryKey = []
609
-
610
- // 搜索键值数组
611
- const NSearchKeys = []
612
- // 搜索数组
613
- const NSearchValues = []
614
-
615
- // 参数中是否有自定义搜索参数
616
- const hasNSearch = $n_has(query, 'n_search')
617
- if (hasNSearch) {
618
- // 删除在搜索中存在的参数键值
619
- $n_forIn(query.n_search, function (item, key) {
620
- if ($n_has(query, key)) {
621
- delete query[key]
622
- }
623
- })
624
- }
625
-
626
- // 如果允许从参数中获取搜索值
627
- if (o.searchFromQuery) {
628
-
629
- $n_forEach(rawSearchOptions, function (item, index) {
630
-
631
- const valueItem = tableSearchValue.value[index]
632
-
633
- // 如果传参在搜素 n_search 参数中
634
- if (hasNSearch && $n_has(query.n_search, item.name)) {
635
- const newSearchItem = query.n_search[item.name]
636
- if ($n_isValidArray(newSearchItem)) {
637
- valueItem[0].compare = newSearchItem[0].compare
638
- valueItem[0].value = newSearchItem[0].value
639
-
640
- if (newSearchItem.length > 1) {
641
- valueItem[1].compare = newSearchItem[1].compare
642
- valueItem[1].value = newSearchItem[1].value
643
- }
644
- }
645
- // 设置搜索的 key
646
- NSearchKeys.push(item.name)
647
-
648
- // 如果传参在搜索参数中
649
- } else if ($n_has(query, item.name)) {
650
- // 设置单个搜索值
651
- setItemValue(valueItem, $n_isRequired(query[item.name]) ? query[item.name] : '')
652
- // 设置参数中搜索的 key
653
- searchQueryKey.push(item.name)
654
- }
655
- })
656
-
657
- $n_forEach(searchQueryKey, function (key) {
658
- delete query[key]
659
- })
660
-
661
- if (hasNSearch) {
662
- $n_forIn(query.n_search, function(item, key) {
663
- if (
664
- NSearchKeys.indexOf(key) === -1
665
- && $n_isValidArray(item)
666
- ) {
667
- item[0].field = key
668
- NSearchValues.push(item[0])
669
-
670
- if (item.length > 1) {
671
- item[1].field = key
672
- NSearchValues.push(item[1])
673
- }
674
- }
675
- })
676
- }
677
-
678
- } else {
679
- $n_forIn(query.n_search, function(item, key) {
680
- if ($n_isValidArray(item)) {
681
- item[0].field = key
682
- NSearchValues.push(item[0])
683
- if (item.length > 1) {
684
- item[1].field = key
685
- NSearchValues.push(item[1])
686
- }
687
- }
688
- })
689
- }
690
-
691
- if (NSearchValues.length) {
692
- query.n_search = NSearchValues
693
- } else if (hasNSearch) {
694
- delete query.n_search
695
- }
696
-
697
- tableRequestQuery = query
698
- return
699
- }
700
-
701
- tableRequestQuery = {}
702
- }
703
-
704
-
705
- /**
706
- * 表格是否已加载
707
- */
708
- function isTableLoaded() {
709
- return _isTableLoaded
710
- }
711
-
712
- /**
713
- * 表格加载(只加载一次)
714
- */
715
- async function tableLoad() {
716
-
717
- // 如果表格已加载过了
718
- if (_isTableLoaded) {
719
- // 则无任何操作
720
- return
721
- }
722
-
723
- // 表格重新加载
724
- await tableReload()
725
- }
726
-
727
- /**
728
- * 表格重新加载
729
- */
730
- async function tableReload() {
731
-
732
- // 表格已加载
733
- _isTableLoaded = true
734
-
735
- if (! $route.fullPath) {
736
- return
737
- }
738
-
739
- // 请求表格合计
740
- if (o.summary) {
741
- isRequestSummary = true
742
- }
743
-
744
- // 请求表格数据
745
- // $tableRef?.requestServerInteraction({
746
- // pagination: o.pagination,
747
- // })
748
- await tableRequest({
749
- pagination: o.pagination,
750
- })
751
-
752
- // 清空表格已选数据
753
- if (o.refreshResetSelected) {
754
- tableSelected.value = []
755
- }
756
- }
757
-
758
- /**
759
- * 表格刷新
760
- */
761
- async function tableRefresh() {
762
-
763
- if (! $route.fullPath) {
764
- return
765
- }
766
-
767
- // 请求表格合计
768
- if (o.summary) {
769
- isRequestSummary = true
770
- }
771
-
772
- // 请求表格数据
773
- // $tableRef.requestServerInteraction()
774
- await tableRequest({
775
- pagination: tablePagination.value,
776
- })
777
-
778
- // 清空表格已选数据
779
- if (o.refreshResetSelected) {
780
- tableSelected.value = []
781
- }
782
- }
783
-
784
- /**
785
- * 表格搜索重置
786
- */
787
- function tableSearchReset(reload = true) {
788
-
789
- const newValue = []
790
-
791
- $n_forEach(rawSearchOptions, function (item, index) {
792
- // 如果该搜索条件是隐藏的
793
- if (item.hide) {
794
- newValue.push(tableSearchValue.value[index])
795
- // 否则为初始值
796
- } else {
797
- newValue.push(rawTableSearchValue[index])
798
- }
799
- })
800
-
801
- // 还原表格搜索数据
802
- tableSearchValue.value = $n_cloneDeep(newValue)
803
-
804
- // 表格重新加载
805
- if (reload) {
806
- tableReload().finally()
807
- }
808
- }
809
-
810
- /**
811
- * 获取表格请求数据
812
- */
813
- function getTableRequestData(props, isSummary = undefined) {
814
-
815
- // 解构数据
816
- const {
817
- // filter,
818
- pagination: {
819
- // 页码
820
- page,
821
- // 每页的数据条数
822
- rowsPerPage,
823
- // 排序字段
824
- sortBy,
825
- // 是否降序排列
826
- descending,
827
- }
828
- } = props
829
-
830
- // 请求数据
831
- const data = {
832
- // 页码
833
- page,
834
- // 每页的数据条数
835
- per_page: rowsPerPage,
836
- }
837
-
838
- // 如果排序字段是有效值
839
- if ($n_isValidValue(sortBy)) {
840
- Object.assign(data, {
841
- // 排序字段
842
- order_by: sortBy,
843
- // 是否降序排列
844
- is_desc: descending ? 1 : 0,
845
- })
846
- }
847
-
848
- // 合并参数
849
- $n_forIn(Object.assign({}, rawQuery, tableRequestQuery, o.data), function(value, key) {
850
- // 如果有值
851
- if ($n_isRequired(value)) {
852
- data[key] = value
853
- }
854
- })
855
-
856
- // 获取搜索值
857
- const search = formatValue(rawSearchOptions, tableSearchValue.value)
858
- if ($n_isValidArray(search)) {
859
- data.n_search = $n_has(data, 'n_search') ? $n_concat(data.n_search, search) : search
860
- }
861
-
862
- if ($n_isNil(isSummary)) {
863
- isSummary = isRequestSummary
864
- }
865
-
866
- // 如果请求表格合计
867
- if (isSummary) {
868
- data.summary = 1
869
- }
870
-
871
- return data
872
- }
873
-
874
- /**
875
- * 请求数据
876
- */
877
- async function tableRequest(props) {
878
-
879
- // 加载
880
- tableLoading.value = true
881
-
882
- // 解构数据
883
- const {
884
- // filter,
885
- pagination: {
886
- // 页码
887
- page,
888
- // 每页的数据条数
889
- rowsPerPage,
890
- // 排序字段
891
- sortBy,
892
- // 是否降序排列
893
- descending,
894
- }
895
- } = props
896
-
897
- // http 请求参数
898
- const httpOptions = Object.assign({
899
- // 请求数据
900
- url: $n_isValidString(o.url) ? o.url : $route.path,
901
- // 请求数据
902
- data: getTableRequestData(props, isRequestSummary),
903
- // ~~~~~~ 先开启防抖, 如果后期遇到表格加载不出来的情况, 再关闭防抖
904
- // 关闭防抖(允许重复请求)
905
- debounce: false,
906
- }, o.httpSettings)
907
-
908
- const { status, data: res } = $n_isFunction(o.request)
909
- // 如果有自定义请求方法
910
- ? await $n_runAsync(o.request)({
911
- // http 请求参数
912
- httpOptions,
913
- // 表格声明属性
914
- props,
915
- // 表格行数据
916
- rows: tableRows,
917
- // 表格已选数据
918
- selected: tableSelected,
919
- })
920
- // 否则请求服务器
921
- : await $n_http(httpOptions)
922
-
923
- // 请求成功
924
- if (status) {
925
-
926
- const {
927
- // 返回数据
928
- rows,
929
- // 数据总数
930
- total,
931
- } = res
932
-
933
- // 如果请求表格合计
934
- if (isRequestSummary) {
935
- const summary = $n_get(res, 'summary')
936
- tableSummary.value = $n_isValidObject(summary) ? summary : null
937
- }
938
-
939
- // 更新页码
940
- tablePagination.value.page = page
941
- // 更新每页的数据条数
942
- tablePagination.value.rowsPerPage = rowsPerPage
943
- // 更新数据总数
944
- tablePagination.value.rowsNumber = total
945
- // 更新排序字段
946
- tablePagination.value.sortBy = sortBy
947
- // 更新是否降序排列
948
- tablePagination.value.descending = descending
949
-
950
- // 格式化单条数据
951
- if ($n_isFunction(o.formatRow)) {
952
- $n_forEach(rows, function(row) {
953
- o.formatRow({
954
- row,
955
- rows: tableRows,
956
- selected: tableSelected,
957
- })
958
- })
959
- }
960
-
961
- // 清除现有数据并添加新数据
962
- tableRows.value.splice(0, tableRows.value.length, ...rows)
963
- }
964
-
965
- // 取消请求表格合计
966
- isRequestSummary = false
967
-
968
- // 取消加载
969
- tableLoading.value = false
970
- }
971
-
972
- /**
973
- * 单击表格行
974
- */
975
- function _tableRowClick(e, row) {
976
-
977
- // 如果选择类型为无
978
- if (tableSelection.value === 'none') {
979
- // 则无任何操作
980
- return
981
- }
982
-
983
- const opt = {}
984
- opt[o.rowKey] = row[o.rowKey]
985
-
986
- // 获取当前数据索引
987
- const itemIndex = $n_findIndex(tableSelected.value, opt)
988
-
989
- // 如果不存在, 则添加
990
- if (itemIndex === -1) {
991
-
992
- // 如果选择类型为单选
993
- if (tableSelection.value === 'single') {
994
- tableSelected.value = [ row ]
995
-
996
- // 否则为多选
997
- } else {
998
- tableSelected.value.push(row)
999
- }
1000
-
1001
- // 否则删除
1002
- } else {
1003
- tableSelected.value.splice(itemIndex, 1)
1004
- }
1005
- }
1006
- function tableRowClick(...e) {
1007
-
1008
- // 单击表格行
1009
- _tableRowClick(...e)
1010
-
1011
- // 如果有自定义单击事件
1012
- if ($n_isFunction(o.rowClick)) {
1013
- o.rowClick(...e)
1014
- }
1015
- }
1016
-
1017
- /**
1018
- * 双击表格行
1019
- */
1020
- function _tableRowDblclick(e, row) {
1021
-
1022
- // 如果选择类型为无
1023
- if (tableSelection.value === 'none') {
1024
- // 则无任何操作
1025
- return
1026
- }
1027
-
1028
- if (
1029
- // 有权限
1030
- hasPowr
1031
- // 有双击的权限按钮
1032
- && tableDbClickPowerBtn.value
1033
- ) {
1034
- $power.powerBtnClick(tableDbClickPowerBtn.value, [ row ])
1035
- }
1036
- }
1037
- function tableRowDblclick(...e) {
1038
-
1039
- // 双击表格行
1040
- _tableRowDblclick(...e)
1041
-
1042
- // 如果有自定义双击表格行事件
1043
- if ($n_isFunction(o.tableRowDblclick)) {
1044
- o.tableRowDblclick(...e)
1045
- }
1046
- }
1047
-
1048
- /**
1049
- * 设置表格搜索参数
1050
- */
1051
- async function setTableSearchOptions(format) {
1052
- tableSearchOptions.value = await getOptions(rawSearchOptions, format)
1053
- }
1054
-
1055
- /**
1056
- * 是否有表格搜索值
1057
- */
1058
- function hasTableSearchValue() {
1059
- return !! formatValue(rawSearchOptions, tableSearchValue.value).length
1060
- }
1061
-
1062
- // ==========【返回】=================================================================================================
1063
-
1064
- const resTable = {
1065
- // 当前路由全路径
1066
- routeFullPath: $route.fullPath,
1067
- // 当前路由路径
1068
- routePath: $route.path,
1069
- // 当前路由参数
1070
- routeQuery: $route.query,
1071
- // 表格行唯一键值
1072
- tableRowKey: o.rowKey,
1073
- // 表格每页显示行数选项
1074
- tableRowsPerPageOptions: o.rowsPerPageOptions,
1075
-
1076
- // 表格加载状态
1077
- tableLoading,
1078
- // 表格选择类型
1079
- tableSelection,
1080
- // 表格分隔栏
1081
- tableSeparator,
1082
- // 表格列数据(对象数组)
1083
- tableColumns,
1084
- // 表格可见列
1085
- tableVisibleColumns,
1086
- // 表格行数据
1087
- tableRows,
1088
- // 表格翻页参数
1089
- tablePagination,
1090
- // 表格已选数据
1091
- tableSelected,
1092
- // 固定在右边的权限按钮列表
1093
- tableFixedPowerBtns,
1094
- // 是否显示固定在右边的权限按钮列表
1095
- showTableFixed,
1096
- // 表格图片标识
1097
- tableImgNames,
1098
-
1099
- // 表格宫格
1100
- tableGrid,
1101
- // 表格合计
1102
- tableSummary,
1103
- // 表格搜索数据
1104
- tableSearchValue,
1105
- // 表格搜索参数
1106
- tableSearchOptions,
1107
-
1108
- // 设置表格传参
1109
- setQuery,
1110
- // 表格是否已加载
1111
- isTableLoaded,
1112
- // 表格加载(只加载一次)
1113
- tableLoad,
1114
- // 表格重新加载
1115
- tableReload,
1116
- // 表格刷新
1117
- tableRefresh,
1118
- // 表格搜索重置
1119
- tableSearchReset,
1120
- // 获取表格请求数据
1121
- getTableRequestData,
1122
- // 表格请求数据
1123
- tableRequest,
1124
- // 表格单击表格行
1125
- tableRowClick,
1126
- // 表格双击表格行
1127
- tableRowDblclick,
1128
- // 设置表格搜索参数
1129
- setTableSearchOptions,
1130
-
1131
- // 是否有表格搜索值
1132
- hasTableSearchValue,
1133
-
1134
- // 获取当前路由
1135
- getRoute() {
1136
- return $route
1137
- },
1138
- // 重新创建表格
1139
- reCreate,
1140
- }
1141
-
1142
- if (hasPowr) {
1143
- $power.update(function(data, _data) {
1144
- _data.$table = resTable
1145
- })
1146
- }
1147
-
1148
- // 提供可以被后代组件注入的值
1149
- provide(NTableKey, resTable)
1150
-
1151
- return resTable
1152
- }
1153
-
1154
- /**
1155
- * 获取表格配置
1156
- */
1157
- function config(routePath, path, defaultValue) {
1158
- return $n_cloneDeep($n_get(tablesConfig, $n_slash(routePath, 'start', false) + (path ? '.' + path : ''), defaultValue))
1159
- }
1160
-
1161
- /**
1162
- * 业务表格
1163
- */
1164
- const $table = {
1165
- // 创建表格
1166
- create,
1167
- // 获取表格配置
1168
- config,
1169
- }
1170
-
1171
- export default $table
1
+ import { ref, computed, provide, inject, watch } from 'vue'
2
+ import { useQuasar } from 'quasar'
3
+
4
+ import $n_has from 'lodash/has'
5
+ import $n_get from 'lodash/get'
6
+ import $n_cloneDeep from 'lodash/cloneDeep'
7
+ import $n_merge from 'lodash/merge'
8
+ import $n_isFunction from 'lodash/isFunction'
9
+ import $n_findIndex from 'lodash/findIndex'
10
+ import $n_uniq from 'lodash/uniq'
11
+ import $n_concat from 'lodash/concat'
12
+ import $n_isNil from 'lodash/isNil'
13
+
14
+ import $n_router from '@netang/utils/vue/router'
15
+
16
+ import $n_forEach from '@netang/utils/forEach'
17
+ import $n_isValidArray from '@netang/utils/isValidArray'
18
+ import $n_isValidString from '@netang/utils/isValidString'
19
+ import $n_indexOf from '@netang/utils/indexOf'
20
+ import $n_storage from '@netang/utils/storage'
21
+
22
+ import $n_isRequired from '@netang/utils/isRequired'
23
+ import $n_forIn from '@netang/utils/forIn'
24
+ import $n_runAsync from '@netang/utils/runAsync'
25
+ import $n_isValidObject from '@netang/utils/isValidObject'
26
+ import $n_isValidValue from '@netang/utils/isValidValue'
27
+ import $n_slash from '@netang/utils/slash'
28
+ import $n_http from '@netang/utils/http'
29
+
30
+ import $n_$power from './$power'
31
+ import $n_dict from './dict'
32
+ import $n_price from './price'
33
+ import $n_getTime from './getTime'
34
+
35
+ import { configs } from './config'
36
+
37
+ import {
38
+ // 设置单个搜索值
39
+ setItemValue,
40
+ // 从表格列获取原始值
41
+ getRawData,
42
+ // 获取参数
43
+ getOptions,
44
+ // 格式化值
45
+ formatValue,
46
+ } from './useSearch'
47
+
48
+ import { NRenderKey, NPowerKey, NTableKey } from './symbols'
49
+
50
+ const {
51
+ // 表格配置
52
+ tablesConfig,
53
+ } = configs
54
+
55
+ /**
56
+ * 创建表格
57
+ */
58
+ function create(options) {
59
+
60
+ // ==========【数据】=================================================================================================
61
+
62
+ // quasar 对象
63
+ const $q = useQuasar()
64
+
65
+ // 每页显示行数选项
66
+ const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
67
+
68
+ // 原始参数
69
+ const rawOptions = {
70
+ // 路由路径
71
+ path: '',
72
+ // 请求地址(默认为 path)
73
+ url: '',
74
+ // 路由参数
75
+ query: {},
76
+ // 附加请求数据
77
+ data: {},
78
+ // 表格行唯一键值
79
+ rowKey: 'id',
80
+ // 选择类型, 可选值 none single(默认) multiple
81
+ // selection: '',
82
+ // 分隔栏, 可选值 horizontal vertical cell none
83
+ separator: 'cell',
84
+ // 初始已选数据
85
+ selected: [],
86
+ // 初始表格加载状态
87
+ loading: false,
88
+ // 表格列数据(对象数组)
89
+ columns: [],
90
+ // 初始可见列
91
+ visibleColumns: [],
92
+ // 表格行数据
93
+ rows: [],
94
+ // 表格翻页参数
95
+ pagination: {
96
+ // 页码
97
+ page: 1,
98
+ // 每页的数据条数
99
+ rowsPerPage: $n_has(options, 'rowsPerPageOptions') ? options.rowsPerPageOptions[0] : rowsPerPageOptions[0],
100
+ // 数据总数(服务器返回)
101
+ rowsNumber: 1,
102
+ // 排序字段
103
+ sortBy: null,
104
+ // sortBy: 'id',
105
+ // 是否降序排列
106
+ descending: true,
107
+ },
108
+ // 每页显示行数选项
109
+ rowsPerPageOptions,
110
+ // 自定义请求方法
111
+ request: null,
112
+ // 格式化单条数据
113
+ formatRow: null,
114
+ // http 设置
115
+ httpSettings: {},
116
+ // 是否开启初始搜素
117
+ search: true,
118
+ // 是否开启合计
119
+ summary: false,
120
+ // 从参数中获取搜索值
121
+ searchFromQuery: true,
122
+ // 是否显示宫格
123
+ showGrid: true,
124
+ // 是否显示可见列
125
+ showVisibleColumns: true,
126
+ // 是否开启缓存
127
+ cache: true,
128
+ // 是否刷新后清空已选数据
129
+ refreshResetSelected: true,
130
+
131
+ // 单击表格行事件
132
+ rowClick: null,
133
+ // 双击表格行事件
134
+ rowDblClick: null,
135
+ }
136
+
137
+ let o
138
+ let $power
139
+ let hasPowr
140
+ let $render
141
+ let $route
142
+ let hasPowerBtns
143
+ let tableSelected
144
+ let isCache
145
+ let cacheName
146
+ let tableColumns
147
+ let tableImgNames
148
+
149
+ // 获取可见列缓存
150
+ let visibleColumnsCache
151
+ // 表格可见列
152
+ let tableVisibleColumns
153
+ // 表格加载状态
154
+ let tableLoading
155
+ // 表格行数据
156
+ let tableRows
157
+ // 表格翻页参数
158
+ let tablePagination
159
+ // 表格宫格
160
+ let tableGrid
161
+ // 表格请求参数(将表格传参中的搜索参数剥离掉, 剩下的直接当做参数传递给服务器)
162
+ let tableRequestQuery
163
+ // 是否请求表格合计
164
+ let isRequestSummary
165
+ // 表格合计
166
+ let tableSummary
167
+ // 表格选择类型
168
+ let tableSelection
169
+ // 表格分隔栏
170
+ let tableSeparator
171
+
172
+ // 原始参数
173
+ let rawQuery
174
+ // 原始表格搜索参数
175
+ let rawSearchOptions
176
+ // 原始表格搜索值(空表格搜索值, 用于搜索重置)
177
+ let rawTableSearchValue
178
+ // 首次表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
179
+ let firstTableSearchValue
180
+
181
+ // 表格搜索数据值
182
+ let tableSearchValue
183
+ // 表格搜索参数
184
+ let tableSearchOptions
185
+ // 是否已加载
186
+ let _isTableLoaded
187
+
188
+ // 是否已生成数据
189
+ let _isCreated = false
190
+
191
+ // 创建表格
192
+ reCreate(options)
193
+
194
+ // 已生成数据
195
+ _isCreated = true
196
+
197
+ // ==========【方法】================================================================================================
198
+
199
+ /**
200
+ * 重新创建表格
201
+ */
202
+ function reCreate(options) {
203
+
204
+ // 获取参数
205
+ o = $n_merge({}, rawOptions, options)
206
+
207
+ // 获取权限注入
208
+ $power = $n_has(options, '$power') ? options.$power : (_isCreated ? $power : inject(NPowerKey))
209
+ hasPowr = !! $power
210
+
211
+ // 获取渲染注入
212
+ $render = $n_has(options, '$render') ? options.$render : (_isCreated ? $render : inject(NRenderKey))
213
+ if (!! $render) {
214
+ // 如果有表格传参, 则合并参数
215
+ const tableProps = $n_get($render, 'props.tableProps')
216
+ if ($n_isValidObject(tableProps)) {
217
+ $n_merge(o, tableProps)
218
+ }
219
+ }
220
+
221
+ // 获取选择类型(默认 single)
222
+ if (! $n_has(o, 'selection') || ! $n_isValidString(o.selection)) {
223
+ if (hasPowr) {
224
+ o.selection = $n_get($power, 'powerPage.data.selection')
225
+ if (! $n_isValidString(o.selection)) {
226
+ o.selection = 'single'
227
+ }
228
+ } else {
229
+ o.selection = 'single'
230
+ }
231
+ }
232
+
233
+ // 获取权限路由
234
+ $route = $n_isValidString(o.path) ?
235
+ // 如果为自定义路由
236
+ $n_router.resolve({
237
+ path: o.path,
238
+ query: $n_isValidObject(o.query) ? o.query : {},
239
+ })
240
+ // 否则获取当前路由
241
+ : (hasPowr ? $power.getRoute() : $n_router.getRoute())
242
+
243
+ // 是否有权限按钮
244
+ const _hasPowerBtns = hasPowr ? $power.powerBtns.value.length : false
245
+ if (_isCreated) {
246
+ hasPowerBtns.value = _hasPowerBtns
247
+ } else {
248
+ hasPowerBtns = ref(_hasPowerBtns)
249
+ }
250
+
251
+ // 表格已选数据
252
+ if (hasPowr) {
253
+ tableSelected = $power.tableSelected
254
+ } else if (_isCreated) {
255
+ tableSelected.value = []
256
+ } else {
257
+ tableSelected = ref([])
258
+ }
259
+ if ($n_isValidArray(o.selected)) {
260
+ tableSelected.value = o.selected
261
+ }
262
+
263
+ // 是否开启缓存
264
+ isCache = !! o.cache
265
+
266
+ // 缓存名
267
+ cacheName = $route.path ? $route.path : ($n_isValidString(o.cache) ? o.cache : '')
268
+
269
+ // 表格列
270
+ const _tableColumns = []
271
+
272
+ // 如果有权限按钮
273
+ if (hasPowerBtns.value) {
274
+ // 添加操作列
275
+ o.columns.push({
276
+ label: '操作',
277
+ name: 'settings',
278
+ })
279
+ }
280
+
281
+ // 表格图片标识数组
282
+ if (_isCreated) {
283
+ tableImgNames.value = []
284
+ } else {
285
+ tableImgNames = ref([])
286
+ }
287
+
288
+ // 设置表格列数据
289
+ // 设置列参数
290
+ $n_forEach(o.columns, function(item) {
291
+
292
+ if (
293
+ ! $n_has(item, 'field')
294
+ && $n_has(item, 'name')
295
+ ) {
296
+ item.field = item.name
297
+ }
298
+
299
+ if (! $n_has(item, 'align')) {
300
+ item.align = 'left'
301
+ }
302
+
303
+ // 是否隐藏
304
+ item.hide = $n_get(item, 'hide') === true
305
+
306
+ // 如果有显示项
307
+ if ($n_get(item, 'visible') !== false) {
308
+ o.visibleColumns.push(item.field)
309
+ }
310
+
311
+ // 如果有时间戳
312
+ if ($n_has(item, 'time')) {
313
+ item.format = val => $n_getTime(val, { format: item.time === true ? `YYYY-MM-DD HH:mm` : item.time }, '-')
314
+
315
+ // 如果有数据字典
316
+ } else if ($n_has(item, 'dict')) {
317
+ item.format = val => $n_dict(item.dict, val)
318
+
319
+ // 如果有图片
320
+ } else if ($n_has(item, 'img') && item.img === true) {
321
+ tableImgNames.value.push(item.name)
322
+
323
+ // 如果有价格
324
+ } else if ($n_has(item, 'price')) {
325
+ item.format = val => $n_price(val)
326
+ }
327
+
328
+ // 如果有路由
329
+ if ($n_get(item, 'route')) {
330
+ // 如果该值在当前路由路径中, 则显示
331
+ if ($n_indexOf($route.fullPath, item.route) > -1) {
332
+ _tableColumns.push(item)
333
+ }
334
+
335
+ } else {
336
+ _tableColumns.push(item)
337
+ }
338
+ })
339
+
340
+ // 获取可见列缓存
341
+ visibleColumnsCache = o.showVisibleColumns && isCache ? $n_storage.get('table:visible_columns:' + cacheName) : []
342
+
343
+ // 表格可见列
344
+ const _tableVisibleColumns = Array.isArray(visibleColumnsCache) ? visibleColumnsCache : $n_uniq([...o.visibleColumns])
345
+
346
+ // 表格翻页参数
347
+ const _tablePagination = $route.fullPath ? o.pagination : {}
348
+
349
+ // 表格宫格
350
+ const _tableGrid = o.showGrid && isCache ? $n_storage.get('table:grid:' + cacheName) === true : false
351
+
352
+ // 获取原始数据
353
+ const r = getRawData(_tableColumns, Object.assign({}, $route.query), o.searchFromQuery)
354
+ // 原始参数
355
+ rawQuery = r.rawQuery
356
+ // 原始表格搜索参数
357
+ rawSearchOptions = r.rawSearchOptions
358
+ // 原始表格搜索值(空表格搜索值, 用于搜索重置)
359
+ rawTableSearchValue = r.rawTableSearchValue
360
+ // 首次表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
361
+ firstTableSearchValue = r.firstTableSearchValue
362
+
363
+ // 表格搜索数据值
364
+ const _tableSearchValue = $route.fullPath ? firstTableSearchValue : []
365
+
366
+ if (_isCreated) {
367
+
368
+ // 表格列
369
+ tableColumns.value = _tableColumns
370
+
371
+ // 表格可见列
372
+ tableVisibleColumns.value = _tableVisibleColumns
373
+
374
+ // 表格加载状态
375
+ tableLoading.value = o.loading
376
+
377
+ // 表格行数据
378
+ tableRows.value = o.rows
379
+
380
+ // 表格翻页参数
381
+ tablePagination.value = _tablePagination
382
+
383
+ // 表格宫格
384
+ tableGrid.value = _tableGrid
385
+
386
+ // 表格合计
387
+ tableSummary.value = null
388
+
389
+ // 表格选择类型
390
+ tableSelection.value = o.selection
391
+
392
+ // 表格分隔栏
393
+ tableSeparator.value = o.separator
394
+
395
+ // 表格搜索数据值
396
+ tableSearchValue.value = _tableSearchValue
397
+
398
+ // 表格搜索参数
399
+ tableSearchOptions.value = null
400
+
401
+ } else {
402
+
403
+ // 表格列
404
+ tableColumns = ref(_tableColumns)
405
+
406
+ // 表格可见列
407
+ tableVisibleColumns = ref(_tableVisibleColumns)
408
+
409
+ // 表格加载状态
410
+ tableLoading = ref(o.loading)
411
+
412
+ // 表格行数据
413
+ tableRows = ref(o.rows)
414
+
415
+ // 表格翻页参数
416
+ tablePagination = ref(_tablePagination)
417
+
418
+ // 表格宫格
419
+ tableGrid = ref(_tableGrid)
420
+
421
+ // 表格合计
422
+ tableSummary = ref(null)
423
+
424
+ // 表格选择类型
425
+ tableSelection = ref(o.selection)
426
+
427
+ // 表格分隔栏
428
+ tableSeparator = ref(o.separator)
429
+
430
+ // 表格搜索数据值
431
+ tableSearchValue = ref(_tableSearchValue)
432
+
433
+ // 表格搜索参数
434
+ tableSearchOptions = ref(null)
435
+ }
436
+
437
+ // 表格请求参数(将表格传参中的搜索参数剥离掉, 剩下的直接当做参数传递给服务器)
438
+ tableRequestQuery = {}
439
+
440
+ // 是否请求表格合计
441
+ isRequestSummary = false
442
+
443
+ // 是否已加载
444
+ _isTableLoaded = false
445
+
446
+ // 如果开启搜索
447
+ if (o.search) {
448
+ // 设置表格搜索参数
449
+ setTableSearchOptions()
450
+ .finally()
451
+ }
452
+
453
+ if (_isCreated) {
454
+
455
+ // 重新赋值
456
+ Object.assign(resTable, {
457
+ // 当前路由全路径
458
+ routeFullPath: $route.fullPath,
459
+ // 当前路由路径
460
+ routePath: $route.path,
461
+ // 当前路由参数
462
+ routeQuery: $route.query,
463
+ // 表格行唯一键值
464
+ tableRowKey: o.rowKey,
465
+ // 表格每页显示行数选项
466
+ tableRowsPerPageOptions: o.rowsPerPageOptions,
467
+ })
468
+
469
+ if (hasPowr) {
470
+ $power.update(function(data, _data) {
471
+ _data.$table = resTable
472
+ })
473
+ }
474
+ }
475
+ }
476
+
477
+ // ==========【计算属性】=============================================================================================
478
+
479
+ /**
480
+ * 固定在表格右边的权限按钮列表
481
+ */
482
+ const tableFixedPowerBtns = computed(function () {
483
+
484
+ const lists = []
485
+
486
+ if (hasPowerBtns.value) {
487
+
488
+ // 先格式化权限按钮列表
489
+ $n_forEach($n_$power.formatBtns($power.powerBtns.value), function(item) {
490
+ // 如果是固定按钮
491
+ if (item.fixed) {
492
+ lists.push(item)
493
+ }
494
+ })
495
+ }
496
+
497
+ return lists
498
+ })
499
+
500
+ /**
501
+ * 获取权限按钮中可双击的按钮
502
+ */
503
+ const tableDbClickPowerBtn = computed(function () {
504
+ if (
505
+ // 如果有权限按钮
506
+ hasPowerBtns.value
507
+ // 非手机模式
508
+ && ! $q.platform.is.mobile
509
+ // 有权限列表
510
+ && $n_isValidArray($power.powerBtns.value)
511
+ ) {
512
+ for (const item of $power.powerBtns.value) {
513
+ if ($n_has(item, 'data.dbclick') === true) {
514
+ return item
515
+ }
516
+ }
517
+ }
518
+ })
519
+
520
+ /**
521
+ * 是否显示固定在右边的权限按钮列表
522
+ */
523
+ const showTableFixed = computed(function () {
524
+ return $n_indexOf(tableVisibleColumns.value, 'settings') > -1
525
+ })
526
+
527
+ // ==========【监听数据】=============================================================================================
528
+
529
+ // #if ! IS_DEV
530
+
531
+ /**
532
+ * 监听表格宫格模式
533
+ */
534
+ watch(tableGrid, function(val) {
535
+ if (o.showGrid && isCache) {
536
+ // 设置宫格模式缓存(永久缓存)
537
+ $n_storage.set('table:grid:' + cacheName, val, 0)
538
+ }
539
+ })
540
+
541
+ /**
542
+ * 监听表格可见列
543
+ */
544
+ watch(tableVisibleColumns, function(val) {
545
+ if (o.showVisibleColumns && isCache) {
546
+ // 设置监听表格可见列缓存(永久缓存)
547
+ $n_storage.set('table:visible_columns:' + cacheName, val, 0)
548
+ }
549
+ })
550
+
551
+ // #endif
552
+
553
+ /**
554
+ * 监听固定在右边的权限按钮列表
555
+ */
556
+ watch(tableFixedPowerBtns, function (lists) {
557
+
558
+ if (! hasPowerBtns.value) {
559
+ return
560
+ }
561
+
562
+ const index = $n_indexOf(tableVisibleColumns.value, 'settings')
563
+
564
+ // 如果有固定在右边的权限按钮列表
565
+ if ($n_isValidArray(lists)) {
566
+
567
+ // 如果设置不在可见列中
568
+ if (index === -1) {
569
+
570
+ // 如果非手机模式
571
+ if (! $q.platform.is.mobile) {
572
+
573
+ // 则将设置加入可见列中
574
+ tableVisibleColumns.value.push('settings')
575
+ }
576
+
577
+ // 否则在可见列中 && 如果是手机模式
578
+ } else if ($q.platform.is.mobile) {
579
+
580
+ // 则将设置从可见列中删除
581
+ tableVisibleColumns.value.splice(index, 1)
582
+ }
583
+
584
+ // 否则如果设置在可见列中
585
+ } else if (index > -1) {
586
+
587
+ // 则将设置从可见列中删除
588
+ tableVisibleColumns.value.splice(index, 1)
589
+ }
590
+
591
+ }, {
592
+ // 立即执行
593
+ immediate: true,
594
+ })
595
+
596
+ // ==========【方法】================================================================================================
597
+
598
+ /**
599
+ * 设置表格传参
600
+ */
601
+ function setQuery(query) {
602
+
603
+ if ($n_isValidObject(query)) {
604
+
605
+ query = $n_cloneDeep(query)
606
+
607
+ // 搜索参数键值数组
608
+ const searchQueryKey = []
609
+
610
+ // 搜索键值数组
611
+ const NSearchKeys = []
612
+ // 搜索数组
613
+ const NSearchValues = []
614
+
615
+ // 参数中是否有自定义搜索参数
616
+ const hasNSearch = $n_has(query, 'n_search')
617
+ if (hasNSearch) {
618
+ // 删除在搜索中存在的参数键值
619
+ $n_forIn(query.n_search, function (item, key) {
620
+ if ($n_has(query, key)) {
621
+ delete query[key]
622
+ }
623
+ })
624
+ }
625
+
626
+ // 如果允许从参数中获取搜索值
627
+ if (o.searchFromQuery) {
628
+
629
+ $n_forEach(rawSearchOptions, function (item, index) {
630
+
631
+ const valueItem = tableSearchValue.value[index]
632
+
633
+ // 如果传参在搜素 n_search 参数中
634
+ if (hasNSearch && $n_has(query.n_search, item.name)) {
635
+ const newSearchItem = query.n_search[item.name]
636
+ if ($n_isValidArray(newSearchItem)) {
637
+ valueItem[0].compare = newSearchItem[0].compare
638
+ valueItem[0].value = newSearchItem[0].value
639
+
640
+ if (newSearchItem.length > 1) {
641
+ valueItem[1].compare = newSearchItem[1].compare
642
+ valueItem[1].value = newSearchItem[1].value
643
+ }
644
+ }
645
+ // 设置搜索的 key
646
+ NSearchKeys.push(item.name)
647
+
648
+ // 如果传参在搜索参数中
649
+ } else if ($n_has(query, item.name)) {
650
+ // 设置单个搜索值
651
+ setItemValue(valueItem, $n_isRequired(query[item.name]) ? query[item.name] : '')
652
+ // 设置参数中搜索的 key
653
+ searchQueryKey.push(item.name)
654
+ }
655
+ })
656
+
657
+ $n_forEach(searchQueryKey, function (key) {
658
+ delete query[key]
659
+ })
660
+
661
+ if (hasNSearch) {
662
+ $n_forIn(query.n_search, function(item, key) {
663
+ if (
664
+ NSearchKeys.indexOf(key) === -1
665
+ && $n_isValidArray(item)
666
+ ) {
667
+ item[0].field = key
668
+ NSearchValues.push(item[0])
669
+
670
+ if (item.length > 1) {
671
+ item[1].field = key
672
+ NSearchValues.push(item[1])
673
+ }
674
+ }
675
+ })
676
+ }
677
+
678
+ } else {
679
+ $n_forIn(query.n_search, function(item, key) {
680
+ if ($n_isValidArray(item)) {
681
+ item[0].field = key
682
+ NSearchValues.push(item[0])
683
+ if (item.length > 1) {
684
+ item[1].field = key
685
+ NSearchValues.push(item[1])
686
+ }
687
+ }
688
+ })
689
+ }
690
+
691
+ if (NSearchValues.length) {
692
+ query.n_search = NSearchValues
693
+ } else if (hasNSearch) {
694
+ delete query.n_search
695
+ }
696
+
697
+ tableRequestQuery = query
698
+ return
699
+ }
700
+
701
+ tableRequestQuery = {}
702
+ }
703
+
704
+
705
+ /**
706
+ * 表格是否已加载
707
+ */
708
+ function isTableLoaded() {
709
+ return _isTableLoaded
710
+ }
711
+
712
+ /**
713
+ * 表格加载(只加载一次)
714
+ */
715
+ async function tableLoad() {
716
+
717
+ // 如果表格已加载过了
718
+ if (_isTableLoaded) {
719
+ // 则无任何操作
720
+ return
721
+ }
722
+
723
+ // 表格重新加载
724
+ await tableReload()
725
+ }
726
+
727
+ /**
728
+ * 表格重新加载
729
+ */
730
+ async function tableReload() {
731
+
732
+ // 表格已加载
733
+ _isTableLoaded = true
734
+
735
+ if (! $route.fullPath) {
736
+ return
737
+ }
738
+
739
+ // 请求表格合计
740
+ if (o.summary) {
741
+ isRequestSummary = true
742
+ }
743
+
744
+ // 请求表格数据
745
+ // $tableRef?.requestServerInteraction({
746
+ // pagination: o.pagination,
747
+ // })
748
+ await tableRequest({
749
+ pagination: o.pagination,
750
+ })
751
+
752
+ // 清空表格已选数据
753
+ if (o.refreshResetSelected) {
754
+ tableSelected.value = []
755
+ }
756
+ }
757
+
758
+ /**
759
+ * 表格刷新
760
+ */
761
+ async function tableRefresh() {
762
+
763
+ if (! $route.fullPath) {
764
+ return
765
+ }
766
+
767
+ // 请求表格合计
768
+ if (o.summary) {
769
+ isRequestSummary = true
770
+ }
771
+
772
+ // 请求表格数据
773
+ // $tableRef.requestServerInteraction()
774
+ await tableRequest({
775
+ pagination: tablePagination.value,
776
+ })
777
+
778
+ // 清空表格已选数据
779
+ if (o.refreshResetSelected) {
780
+ tableSelected.value = []
781
+ }
782
+ }
783
+
784
+ /**
785
+ * 表格搜索重置
786
+ */
787
+ function tableSearchReset(reload = true) {
788
+
789
+ const newValue = []
790
+
791
+ $n_forEach(rawSearchOptions, function (item, index) {
792
+ // 如果该搜索条件是隐藏的
793
+ if (item.hide) {
794
+ newValue.push(tableSearchValue.value[index])
795
+ // 否则为初始值
796
+ } else {
797
+ newValue.push(rawTableSearchValue[index])
798
+ }
799
+ })
800
+
801
+ // 还原表格搜索数据
802
+ tableSearchValue.value = $n_cloneDeep(newValue)
803
+
804
+ // 表格重新加载
805
+ if (reload) {
806
+ tableReload().finally()
807
+ }
808
+ }
809
+
810
+ /**
811
+ * 获取表格请求数据
812
+ */
813
+ function getTableRequestData(props, isSummary = undefined) {
814
+
815
+ // 解构数据
816
+ const {
817
+ // filter,
818
+ pagination: {
819
+ // 页码
820
+ page,
821
+ // 每页的数据条数
822
+ rowsPerPage,
823
+ // 排序字段
824
+ sortBy,
825
+ // 是否降序排列
826
+ descending,
827
+ }
828
+ } = props
829
+
830
+ // 请求数据
831
+ const data = {
832
+ // 页码
833
+ page,
834
+ // 每页的数据条数
835
+ per_page: rowsPerPage,
836
+ }
837
+
838
+ // 如果排序字段是有效值
839
+ if ($n_isValidValue(sortBy)) {
840
+ Object.assign(data, {
841
+ // 排序字段
842
+ order_by: sortBy,
843
+ // 是否降序排列
844
+ is_desc: descending ? 1 : 0,
845
+ })
846
+ }
847
+
848
+ // 合并参数
849
+ $n_forIn(Object.assign({}, rawQuery, tableRequestQuery, o.data), function(value, key) {
850
+ // 如果有值
851
+ if ($n_isRequired(value)) {
852
+ data[key] = value
853
+ }
854
+ })
855
+
856
+ // 获取搜索值
857
+ const search = formatValue(rawSearchOptions, tableSearchValue.value)
858
+ if ($n_isValidArray(search)) {
859
+ data.n_search = $n_has(data, 'n_search') ? $n_concat(data.n_search, search) : search
860
+ }
861
+
862
+ if ($n_isNil(isSummary)) {
863
+ isSummary = isRequestSummary
864
+ }
865
+
866
+ // 如果请求表格合计
867
+ if (isSummary) {
868
+ data.summary = 1
869
+ }
870
+
871
+ return data
872
+ }
873
+
874
+ /**
875
+ * 请求数据
876
+ */
877
+ async function tableRequest(props) {
878
+
879
+ // 加载
880
+ tableLoading.value = true
881
+
882
+ // 解构数据
883
+ const {
884
+ // filter,
885
+ pagination: {
886
+ // 页码
887
+ page,
888
+ // 每页的数据条数
889
+ rowsPerPage,
890
+ // 排序字段
891
+ sortBy,
892
+ // 是否降序排列
893
+ descending,
894
+ }
895
+ } = props
896
+
897
+ // http 请求参数
898
+ const httpOptions = Object.assign({
899
+ // 请求数据
900
+ url: $n_isValidString(o.url) ? o.url : $route.path,
901
+ // 请求数据
902
+ data: getTableRequestData(props, isRequestSummary),
903
+ // ~~~~~~ 先开启防抖, 如果后期遇到表格加载不出来的情况, 再关闭防抖
904
+ // 关闭防抖(允许重复请求)
905
+ debounce: false,
906
+ }, o.httpSettings)
907
+
908
+ const { status, data: res } = $n_isFunction(o.request)
909
+ // 如果有自定义请求方法
910
+ ? await $n_runAsync(o.request)({
911
+ // http 请求参数
912
+ httpOptions,
913
+ // 表格声明属性
914
+ props,
915
+ // 表格行数据
916
+ rows: tableRows,
917
+ // 表格已选数据
918
+ selected: tableSelected,
919
+ })
920
+ // 否则请求服务器
921
+ : await $n_http(httpOptions)
922
+
923
+ // 请求成功
924
+ if (status) {
925
+
926
+ const {
927
+ // 返回数据
928
+ rows,
929
+ // 数据总数
930
+ total,
931
+ } = res
932
+
933
+ // 如果请求表格合计
934
+ if (isRequestSummary) {
935
+ const summary = $n_get(res, 'summary')
936
+ tableSummary.value = $n_isValidObject(summary) ? summary : null
937
+ }
938
+
939
+ // 更新页码
940
+ tablePagination.value.page = page
941
+ // 更新每页的数据条数
942
+ tablePagination.value.rowsPerPage = rowsPerPage
943
+ // 更新数据总数
944
+ tablePagination.value.rowsNumber = total
945
+ // 更新排序字段
946
+ tablePagination.value.sortBy = sortBy
947
+ // 更新是否降序排列
948
+ tablePagination.value.descending = descending
949
+
950
+ // 格式化单条数据
951
+ if ($n_isFunction(o.formatRow)) {
952
+ $n_forEach(rows, function(row) {
953
+ o.formatRow({
954
+ row,
955
+ rows: tableRows,
956
+ selected: tableSelected,
957
+ })
958
+ })
959
+ }
960
+
961
+ // 清除现有数据并添加新数据
962
+ tableRows.value.splice(0, tableRows.value.length, ...rows)
963
+ }
964
+
965
+ // 取消请求表格合计
966
+ isRequestSummary = false
967
+
968
+ // 取消加载
969
+ tableLoading.value = false
970
+ }
971
+
972
+ /**
973
+ * 单击表格行
974
+ */
975
+ function _tableRowClick(e, row) {
976
+
977
+ // 如果选择类型为无
978
+ if (tableSelection.value === 'none') {
979
+ // 则无任何操作
980
+ return
981
+ }
982
+
983
+ const opt = {}
984
+ opt[o.rowKey] = row[o.rowKey]
985
+
986
+ // 获取当前数据索引
987
+ const itemIndex = $n_findIndex(tableSelected.value, opt)
988
+
989
+ // 如果不存在, 则添加
990
+ if (itemIndex === -1) {
991
+
992
+ // 如果选择类型为单选
993
+ if (tableSelection.value === 'single') {
994
+ tableSelected.value = [ row ]
995
+
996
+ // 否则为多选
997
+ } else {
998
+ tableSelected.value.push(row)
999
+ }
1000
+
1001
+ // 否则删除
1002
+ } else {
1003
+ tableSelected.value.splice(itemIndex, 1)
1004
+ }
1005
+ }
1006
+ function tableRowClick(...e) {
1007
+
1008
+ // 单击表格行
1009
+ _tableRowClick(...e)
1010
+
1011
+ // 如果有自定义单击事件
1012
+ if ($n_isFunction(o.rowClick)) {
1013
+ o.rowClick(...e)
1014
+ }
1015
+ }
1016
+
1017
+ /**
1018
+ * 双击表格行
1019
+ */
1020
+ function _tableRowDblclick(e, row) {
1021
+
1022
+ // 如果选择类型为无
1023
+ if (tableSelection.value === 'none') {
1024
+ // 则无任何操作
1025
+ return
1026
+ }
1027
+
1028
+ if (
1029
+ // 有权限
1030
+ hasPowr
1031
+ // 有双击的权限按钮
1032
+ && tableDbClickPowerBtn.value
1033
+ ) {
1034
+ $power.powerBtnClick(tableDbClickPowerBtn.value, [ row ])
1035
+ }
1036
+ }
1037
+ function tableRowDblclick(...e) {
1038
+
1039
+ // 双击表格行
1040
+ _tableRowDblclick(...e)
1041
+
1042
+ // 如果有自定义双击表格行事件
1043
+ if ($n_isFunction(o.tableRowDblclick)) {
1044
+ o.tableRowDblclick(...e)
1045
+ }
1046
+ }
1047
+
1048
+ /**
1049
+ * 设置表格搜索参数
1050
+ */
1051
+ async function setTableSearchOptions(format) {
1052
+ tableSearchOptions.value = await getOptions(rawSearchOptions, format)
1053
+ }
1054
+
1055
+ /**
1056
+ * 是否有表格搜索值
1057
+ */
1058
+ function hasTableSearchValue() {
1059
+ return !! formatValue(rawSearchOptions, tableSearchValue.value).length
1060
+ }
1061
+
1062
+ // ==========【返回】=================================================================================================
1063
+
1064
+ const resTable = {
1065
+ // 当前路由全路径
1066
+ routeFullPath: $route.fullPath,
1067
+ // 当前路由路径
1068
+ routePath: $route.path,
1069
+ // 当前路由参数
1070
+ routeQuery: $route.query,
1071
+ // 表格行唯一键值
1072
+ tableRowKey: o.rowKey,
1073
+ // 表格每页显示行数选项
1074
+ tableRowsPerPageOptions: o.rowsPerPageOptions,
1075
+
1076
+ // 表格加载状态
1077
+ tableLoading,
1078
+ // 表格选择类型
1079
+ tableSelection,
1080
+ // 表格分隔栏
1081
+ tableSeparator,
1082
+ // 表格列数据(对象数组)
1083
+ tableColumns,
1084
+ // 表格可见列
1085
+ tableVisibleColumns,
1086
+ // 表格行数据
1087
+ tableRows,
1088
+ // 表格翻页参数
1089
+ tablePagination,
1090
+ // 表格已选数据
1091
+ tableSelected,
1092
+ // 固定在右边的权限按钮列表
1093
+ tableFixedPowerBtns,
1094
+ // 是否显示固定在右边的权限按钮列表
1095
+ showTableFixed,
1096
+ // 表格图片标识
1097
+ tableImgNames,
1098
+
1099
+ // 表格宫格
1100
+ tableGrid,
1101
+ // 表格合计
1102
+ tableSummary,
1103
+ // 表格搜索数据
1104
+ tableSearchValue,
1105
+ // 表格搜索参数
1106
+ tableSearchOptions,
1107
+
1108
+ // 设置表格传参
1109
+ setQuery,
1110
+ // 表格是否已加载
1111
+ isTableLoaded,
1112
+ // 表格加载(只加载一次)
1113
+ tableLoad,
1114
+ // 表格重新加载
1115
+ tableReload,
1116
+ // 表格刷新
1117
+ tableRefresh,
1118
+ // 表格搜索重置
1119
+ tableSearchReset,
1120
+ // 获取表格请求数据
1121
+ getTableRequestData,
1122
+ // 表格请求数据
1123
+ tableRequest,
1124
+ // 表格单击表格行
1125
+ tableRowClick,
1126
+ // 表格双击表格行
1127
+ tableRowDblclick,
1128
+ // 设置表格搜索参数
1129
+ setTableSearchOptions,
1130
+
1131
+ // 是否有表格搜索值
1132
+ hasTableSearchValue,
1133
+
1134
+ // 获取当前路由
1135
+ getRoute() {
1136
+ return $route
1137
+ },
1138
+ // 重新创建表格
1139
+ reCreate,
1140
+ }
1141
+
1142
+ if (hasPowr) {
1143
+ $power.update(function(data, _data) {
1144
+ _data.$table = resTable
1145
+ })
1146
+ }
1147
+
1148
+ // 提供可以被后代组件注入的值
1149
+ provide(NTableKey, resTable)
1150
+
1151
+ return resTable
1152
+ }
1153
+
1154
+ /**
1155
+ * 获取表格配置
1156
+ */
1157
+ function config(routePath, path, defaultValue) {
1158
+ return $n_cloneDeep($n_get(tablesConfig, $n_slash(routePath, 'start', false) + (path ? '.' + path : ''), defaultValue))
1159
+ }
1160
+
1161
+ /**
1162
+ * 业务表格
1163
+ */
1164
+ const $table = {
1165
+ // 创建表格
1166
+ create,
1167
+ // 获取表格配置
1168
+ config,
1169
+ }
1170
+
1171
+ export default $table