index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="pageWrap bgc">
  3. <div class="content-warp flex-column-page-wrap">
  4. <!-- 公用搜索组件 -->
  5. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"></LeSearchForm>
  6. <!-- LeTable 组件使用 -->
  7. <LeTable
  8. ref="tableRef"
  9. v-model:searchParams="tableOpts.searchParams"
  10. v-bind="tableOpts"
  11. v-model:curRow="tableOpts.curRow"
  12. v-model:checked-options="checkedColumns"
  13. :columns="activeColumns"
  14. >
  15. <template #toolLeft>
  16. <el-button plain :icon="Plus" @click="addHandler" type="primary">新增</el-button>
  17. <el-button plain :icon="Delete" :disabled="curSelectionRows.length === 0" @click="batch_del" type="danger">删除</el-button>
  18. </template>
  19. <template #statusSlot="scope">
  20. <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" @change="() => handleStatusChange(scope.row)"></el-switch>
  21. </template>
  22. <template #actionSlot="{ row }">
  23. <div class="flex flex-align-pack-center">
  24. <LeIcon class="text-lg text-icon-color cursor-pointer" icon-class="icon-processInfo-mage--edit" @click="table_edit(row)" />
  25. <LeIcon class="text-lg ml-2 text-rose-700 cursor-pointer" icon-class="icon-processInfo-iconoir--trash" @click="table_del(row)" />
  26. </div>
  27. </template>
  28. </LeTable>
  29. </div>
  30. <LeFormConfigDialog
  31. v-if="visible"
  32. ref="dialogUserRef"
  33. v-model="visible"
  34. :title="`${isCreate ? '新增' : '编辑'}应用`"
  35. width="600px"
  36. :form-data="activeData"
  37. :form-options="formOptions"
  38. @submit="submitHandler"
  39. />
  40. </div>
  41. </template>
  42. <script lang="tsx" setup>
  43. import app from '@/api/system/app'
  44. import { computed, nextTick, ref, watch } from 'vue'
  45. import { ElMessage, ElMessageBox, ElTree } from 'element-plus'
  46. import { useTablePage } from '@/hooks/useTablePage'
  47. import { Plus, Delete } from '@element-plus/icons-vue'
  48. const visible = ref(false) // 弹窗显示隐藏
  49. const isCreate = ref(true)
  50. const activeData = ref({})
  51. const formsDialog = [
  52. {
  53. prop: 'identification',
  54. label: '应用标识',
  55. itemType: 'input',
  56. rules: [{ required: true, message: '请输入应用标识', trigger: 'blur' }]
  57. },
  58. {
  59. prop: 'name',
  60. label: '应用名称',
  61. itemType: 'input',
  62. rules: [{ required: true, message: '请输入应用名称', trigger: 'blur' }]
  63. },
  64. {
  65. prop: 'secretKey',
  66. label: '应用密钥',
  67. itemType: 'input',
  68. rules: [{ required: true, message: '请输入应用密钥', trigger: 'blur' }]
  69. },
  70. {
  71. prop: 'expire',
  72. label: '授权至',
  73. itemType: 'datePicker',
  74. valueFormat: 'YYYY-MM-DD',
  75. rules: [{ required: true, message: '请输入授权结束日期', trigger: 'blur' }]
  76. },
  77. {
  78. prop: 'status',
  79. label: '应用状态',
  80. itemType: 'switch',
  81. activeText: '正常',
  82. inactiveText: '禁用'
  83. },
  84. {
  85. prop: 'sort',
  86. label: '排序',
  87. itemType: 'inputNumber',
  88. rules: [{ required: true, message: '请输入排序', trigger: 'blur' }]
  89. }
  90. ]
  91. // 新增的表单 和 编辑的表单
  92. const formOptions = computed(() => {
  93. return {
  94. forms: formsDialog,
  95. labelWidth: 120,
  96. span: 30,
  97. showResetBtn: true,
  98. formConfig: {
  99. showCancelBtn: true,
  100. submitLoading: false
  101. }
  102. }
  103. })
  104. const groupFilterText = ref('')
  105. const treeRef = ref<InstanceType<typeof ElTree>>()
  106. // 表格搜索条件
  107. const forms = ref([
  108. {
  109. prop: 'keyword',
  110. label: '应用标识:',
  111. itemType: 'input',
  112. placeholder: '请输入应用标识'
  113. },
  114. {
  115. prop: 'name',
  116. label: '应用名称:',
  117. itemType: 'input',
  118. placeholder: '请输入应用名称'
  119. },
  120. {
  121. prop: 'status',
  122. label: '应用状态:',
  123. itemType: 'select',
  124. placeholder: '请选择应用状态',
  125. options: [
  126. {
  127. label: '禁用',
  128. value: 0
  129. },
  130. {
  131. label: '正常',
  132. value: 1
  133. }
  134. ]
  135. }
  136. ])
  137. // table列表数据请求
  138. const queryList = async () => {
  139. const { options, searchParams } = tableOpts
  140. options.loading = true
  141. try {
  142. const { records: list, total } = await app.appPageApi(searchParams)
  143. tableOpts.total = total
  144. tableOpts.list = list
  145. } catch {
  146. console.log('获取列表数据失败')
  147. tableOpts.total = 0
  148. tableOpts.list = []
  149. options.loading = false // 更改加载中的 loading值
  150. } finally {
  151. options.loading = false
  152. }
  153. }
  154. // table 参数
  155. const columns = [
  156. {
  157. prop: 'identification',
  158. label: '应用标识'
  159. },
  160. {
  161. prop: 'name',
  162. label: '应用名称',
  163. minWidth: 100
  164. },
  165. {
  166. prop: 'secretKey',
  167. label: '应用密钥',
  168. minWidth: 100
  169. },
  170. {
  171. prop: 'status',
  172. label: '应用状态',
  173. minWidth: 60,
  174. slots: {
  175. default: 'statusSlot'
  176. }
  177. },
  178. {
  179. prop: 'sort',
  180. label: '排序',
  181. minWidth: 80
  182. },
  183. // {
  184. // prop: 'updateBy',
  185. // label: '修改人',
  186. // minWidth: 100
  187. // },
  188. // {
  189. // prop: 'updateTime',
  190. // label: '修改时间',
  191. // minWidth: 150
  192. // },
  193. // {
  194. // prop: 'createBy',
  195. // label: '创建人',
  196. // minWidth: 100
  197. // },
  198. {
  199. prop: 'createTime',
  200. label: '创建时间',
  201. minWidth: 150
  202. },
  203. {
  204. prop: 'action',
  205. label: '操作',
  206. align: 'center',
  207. width: 100,
  208. fixed: 'right',
  209. slots: {
  210. default: 'actionSlot'
  211. }
  212. }
  213. ]
  214. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  215. {
  216. options: {
  217. showIndex: false,
  218. defaultExpandAll: true
  219. },
  220. // 需要展示的列
  221. columns,
  222. // 控制列配置
  223. columnsConfig: {
  224. columns
  225. }
  226. },
  227. {
  228. queryList,
  229. fetchImmediate: false
  230. }
  231. )
  232. // 删除
  233. const deleteItem = async ids => {
  234. // try {
  235. await app.appDeleteApi(ids)
  236. ElMessage.success(`删除成功~`)
  237. updateParams()
  238. // } catch (e) {
  239. // console.log('删除失败')
  240. // ElMessage.error(`删除失败~`)
  241. // }
  242. }
  243. // 单个删除
  244. const table_del = (row: any) => {
  245. ElMessageBox.confirm(`确认删除「${row.identification}」这条数据?`, '提示', {
  246. confirmButtonText: '确认',
  247. cancelButtonText: '取消',
  248. type: 'error'
  249. }).then(async () => {
  250. deleteItem([row.id])
  251. })
  252. }
  253. //批量删除
  254. const batch_del = () => {
  255. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  256. ElMessageBox.confirm('是否删除选中数据?', '提示', {
  257. confirmButtonText: '确认',
  258. cancelButtonText: '取消',
  259. type: 'error',
  260. buttonSize: 'default'
  261. }).then(() => {
  262. deleteItem(ids)
  263. })
  264. }
  265. const table_edit = async row => {
  266. isCreate.value = false
  267. activeData.value = { ...row, status: row.status ? true : false }
  268. visible.value = true
  269. }
  270. // 弹窗事件
  271. const submitHandler = async params => {
  272. formOptions.value.formConfig.submitLoading = true
  273. try {
  274. params.status = params.status ? 1 : 0
  275. params.expire = params.expire + ' 00:00:00'
  276. params.id = activeData.value.id ? activeData.value.id : null
  277. await app.appAddOrEditSaveApi(params)
  278. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  279. visible.value = false
  280. updateParams()
  281. formOptions.value.formConfig.submitLoading = false
  282. } catch (e) {
  283. console.log(e)
  284. formOptions.value.formConfig.submitLoading = false
  285. }
  286. }
  287. const addHandler = () => {
  288. isCreate.value = true
  289. activeData.value = {}
  290. visible.value = true
  291. }
  292. const handleStatusChange = (row: any) => {
  293. // 应用状态 0、禁用 1、正常
  294. const status = row.status
  295. let text = Number(row.status) === 0 ? '禁用' : '启用'
  296. ElMessageBox.confirm('请确认是否' + text + '当前数据?', '提示', { type: 'warning' })
  297. .then(async () => {
  298. await app.appStatusApi({ id: row.id, status }) // 接口请求
  299. ElMessage.success(`${text}成功`)
  300. })
  301. .catch(status => {
  302. if (status == 'cancel') {
  303. row.status = Number(row.status) === 0 ? 1 : 0
  304. }
  305. })
  306. }
  307. nextTick(() => {
  308. queryList()
  309. })
  310. watch(groupFilterText, val => {
  311. treeRef.value!.filter(val)
  312. })
  313. </script>