index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <script setup lang="ts" name="Client">
  2. import apis from "@a"
  3. const tableRef = ref()
  4. const modalRef = ref()
  5. const opts = reactive({
  6. columns: [
  7. { field: "id", name: "id", width: 100, isSort: true, visible: false },
  8. { field: "clientId", name: "客户端 ID", visible: true, isSort: false, width: 240 },
  9. { field: "clientKey", name: "客户端 KEY", visible: true, isSort: false, width: 120 },
  10. { field: "clientSecret", name: "客户端 SECRET", visible: true, width: 150, tooltip: true },
  11. { field: "grantType", name: "授权类型", visible: true, isSort: false, width: "auto" },
  12. { field: "deviceType", name: "设备类型", visible: true, isSort: true, width: 100 },
  13. { field: "activeTimeout", name: "活跃超时时间", visible: true, isSort: true, width: 120 },
  14. { field: "timeout", name: "超时时间", visible: true, isSort: false, width: 100 },
  15. { field: "status", name: "状态", visible: true, isSort: false, width: 80 },
  16. { field: "actions", name: `操作`, width: 150 }
  17. ] as any,
  18. queryParams: {
  19. clientKey: undefined,
  20. grantType: undefined,
  21. deviceType: undefined
  22. },
  23. searchFormItems: [
  24. {
  25. field: "clientKey",
  26. label: "客户端KEY",
  27. class: "w-100",
  28. required: false,
  29. placeholder: "请输入客户端KEY",
  30. component: "I",
  31. listeners: {
  32. keyup: (e: KeyboardEvent) => {
  33. if (e.code == "Enter") {
  34. handleQuery()
  35. }
  36. }
  37. },
  38. span: 5
  39. },
  40. {
  41. field: "grantType",
  42. label: "授权类型",
  43. class: "w-100",
  44. required: false,
  45. component: "Dict",
  46. props: {
  47. placeholder: "请选择授权类型",
  48. dictType: "sys_grant_type",
  49. valueIsNumber: false,
  50. type: "select"
  51. },
  52. span: 5
  53. },
  54. {
  55. field: "deviceType",
  56. label: "设备类型",
  57. class: "w-100",
  58. required: false,
  59. component: "Dict",
  60. props: {
  61. placeholder: "请选择设备类型",
  62. dictType: "sys_device_type",
  63. valueIsNumber: false,
  64. type: "select"
  65. },
  66. span: 5
  67. }
  68. ] as any,
  69. permission: "system:client",
  70. handleBtns: [],
  71. handleFuns: {
  72. handleUpdate: () => {
  73. const row = tableRef.value.getSelected()
  74. handleUpdate(row)
  75. },
  76. handleDelete: () => {
  77. const rows = tableRef.value.getSelecteds()
  78. handleDelete(rows)
  79. }
  80. },
  81. customBtns: [],
  82. tableListFun: apis.system.clientApi.list,
  83. getEntityFun: apis.system.clientApi.get,
  84. deleteEntityFun: apis.system.clientApi.del,
  85. exportUrl: apis.system.clientApi.exportUrl,
  86. exportName: "Client",
  87. modalTitle: "客户端",
  88. formItems: [
  89. // {
  90. // field: "clientId",
  91. // label: "客户端编号",
  92. // class: "w-100",
  93. // required: true,
  94. // placeholder: "请输入客户端编号",
  95. // component: "I"
  96. // },
  97. {
  98. field: "clientKey",
  99. label: "客户端KEY",
  100. class: "w-100",
  101. required: true,
  102. placeholder: "请输入客户端KEY",
  103. component: "I"
  104. },
  105. {
  106. field: "clientSecret",
  107. label: "客户端秘钥",
  108. class: "w-100",
  109. required: true,
  110. placeholder: "请输入客户端秘钥",
  111. component: "I"
  112. },
  113. {
  114. field: "grantTypeList",
  115. label: "授权类型",
  116. class: "w-100",
  117. required: true,
  118. component: "Dict",
  119. props: {
  120. dictType: "sys_grant_type",
  121. type: "checkbox",
  122. valueIsNumber: false
  123. }
  124. },
  125. {
  126. field: "deviceType",
  127. label: "设备类型",
  128. class: "w-100",
  129. required: true,
  130. component: "Dict",
  131. props: {
  132. dictType: "sys_device_type",
  133. type: "radio",
  134. valueIsNumber: false
  135. }
  136. },
  137. {
  138. field: "activeTimeout",
  139. label: "活跃超时时间",
  140. class: "w-100",
  141. required: true,
  142. placeholder: "请输入活跃超时时间",
  143. component: "I"
  144. },
  145. {
  146. field: "timeout",
  147. label: "超时时间",
  148. class: "w-100",
  149. required: true,
  150. placeholder: "请输入超时时间",
  151. component: "I"
  152. },
  153. {
  154. field: "status",
  155. label: "状态",
  156. class: "w-100",
  157. required: true,
  158. component: "Dict",
  159. props: {
  160. dictType: "sys_normal_disable",
  161. type: "radio",
  162. valueIsNumber: false
  163. }
  164. }
  165. ] as any,
  166. resetForm: () => {
  167. form.value = emptyFormData.value
  168. },
  169. labelWidth: "90px",
  170. emptyFormData: {
  171. id: undefined,
  172. clientId: undefined,
  173. clientKey: undefined,
  174. clientSecret: undefined,
  175. grantTypeList: undefined,
  176. deviceType: undefined,
  177. activeTimeout: undefined,
  178. timeout: undefined,
  179. status: undefined
  180. }
  181. })
  182. const { queryParams, emptyFormData } = toRefs(opts)
  183. const form = ref<any>(emptyFormData.value)
  184. /** 搜索按钮操作 */
  185. function handleQuery(query?: any) {
  186. query = query || tableRef.value?.getQueryParams() || queryParams.value
  187. addDateRange(query, query.dateRangeCreateTime)
  188. addDateRange(query, query.dateRangeUpdateTime, "UpdateTime")
  189. tableRef.value?.query(query)
  190. }
  191. /** 重置按钮操作 */
  192. function resetQuery(query?: any) {
  193. query = query || tableRef.value?.getQueryParams() || queryParams.value
  194. query.dateRangeCreateTime = [] as any
  195. addDateRange(query, query.dateRangeCreateTime)
  196. query.dateRangeUpdateTime = [] as any
  197. addDateRange(query, query.dateRangeUpdateTime, "UpdateTime")
  198. //
  199. }
  200. /** 修改按钮操作 */
  201. function handleUpdate(row: any) {
  202. tableRef.value.defaultHandleFuns.handleUpdate("", row)
  203. form.value.grantTypeList = form.value.grantType.split(",")
  204. }
  205. /** 删除按钮操作 */
  206. function handleDelete(rows: any[]) {
  207. tableRef.value.defaultHandleFuns.handleDelete("", rows)
  208. }
  209. /** 提交按钮 */
  210. function submitForm() {
  211. form.value.grantType = form.value.grantTypeList.join(",")
  212. apis.system.clientApi.addOrUpdate(form.value).then(() => {
  213. handleQuery()
  214. })
  215. }
  216. </script>
  217. <template>
  218. <div class="app-container">
  219. <VbTable
  220. ref="tableRef"
  221. keyField="id"
  222. :columns="opts.columns"
  223. :handle-perm="opts.permission"
  224. :handle-btns="opts.handleBtns"
  225. :handle-funs="opts.handleFuns"
  226. :search-form-items="opts.searchFormItems"
  227. :custom-btns="opts.customBtns"
  228. :remote-fun="opts.tableListFun"
  229. :get-entity-fun="opts.getEntityFun"
  230. :delete-entity-fun="opts.deleteEntityFun"
  231. :export-url="opts.exportUrl"
  232. :export-name="opts.exportName"
  233. :modal="modalRef"
  234. :reset-form-fun="opts.resetForm"
  235. v-model:form-data="form"
  236. v-model:query-params="queryParams"
  237. :check-multiple="true"
  238. :reset-search-form-fun="resetQuery"
  239. :custom-search-fun="handleQuery">
  240. <template #grantType="{ row }">
  241. <DictTag
  242. type="sys_grant_type"
  243. :value-is-number="false"
  244. :value="row.grantType ? row.grantType.split(',') : []"></DictTag>
  245. </template>
  246. <template #deviceType="{ row }">
  247. <DictTag type="sys_device_type" :value-is-number="false" :value="row.deviceType"></DictTag>
  248. </template>
  249. <template #status="{ row }">
  250. <DictTag type="sys_normal_disable" :value-is-number="false" :value="row.status"></DictTag>
  251. </template>
  252. <template #actions="{ row }">
  253. <vb-tooltip content="修改" placement="top">
  254. <el-button
  255. link
  256. type="primary"
  257. @click="handleUpdate(row)"
  258. v-hasPermission="'system:client:edit'">
  259. <template #icon>
  260. <VbIcon icon-name="notepad-edit" icon-type="duotone" class="fs-3"></VbIcon>
  261. </template>
  262. </el-button>
  263. </vb-tooltip>
  264. <vb-tooltip content="删除" placement="top">
  265. <el-button
  266. link
  267. type="primary"
  268. @click="handleDelete([row])"
  269. v-hasPermission="'system:client:remove'">
  270. <template #icon>
  271. <VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
  272. </template>
  273. </el-button>
  274. </vb-tooltip>
  275. </template>
  276. </VbTable>
  277. <VbModal
  278. v-model:modal="modalRef"
  279. :title="opts.modalTitle"
  280. :form-data="form"
  281. :form-items="opts.formItems"
  282. :form-label-width="opts.labelWidth"
  283. append-to-body
  284. @confirm="submitForm"></VbModal>
  285. </div>
  286. </template>