@netang/quasar 0.2.20 → 0.2.21

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