index.vue 6.8 KB

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