@netang/quasar 0.1.68 → 0.1.71

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