@netang/quasar 0.1.75 → 0.1.76

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