index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <CzrContent
  3. v-model:tableHead="state.query.head"
  4. @handleReset="onReset"
  5. @handleSearch="onSearch"
  6. >
  7. <template #tableTitle>
  8. <div class="flex gap-2.5"></div>
  9. </template>
  10. <template #buttons>
  11. <div class="flex items-center gap-2.5">
  12. <CzrForm class="bm-filter" label-width="0px" @handleEnter="onSearch">
  13. <CzrFormColumn
  14. width="19rem"
  15. class="__czr-table-form-column"
  16. :span="24"
  17. label-width="0px"
  18. v-model:param="state.query.form.time1"
  19. link="date"
  20. type="daterange"
  21. placeholder="租户启用时间"
  22. />
  23. <CzrFormColumn
  24. width="19rem"
  25. class="__czr-table-form-column"
  26. :span="24"
  27. label-width="0px"
  28. v-model:param="state.query.form.time2"
  29. link="date"
  30. type="daterange"
  31. placeholder="租户到期时间"
  32. />
  33. <CzrFormColumn
  34. width="6.68rem"
  35. class="__czr-table-form-column"
  36. :span="24"
  37. label-width="0px"
  38. v-model:param="state.query.form.enabled"
  39. link="select"
  40. :options="DictionaryStore.trueFalseStatus"
  41. placeholder="租户状态"
  42. />
  43. <CzrFormColumn
  44. width="15.63rem"
  45. class="__czr-table-form-column"
  46. :span="24"
  47. label-width="0px"
  48. v-model:param="state.text"
  49. placeholder="输入关键词以检索"
  50. :prefix-icon="Search"
  51. />
  52. <CzrButton type="add" @click="onAdd" />
  53. </CzrForm>
  54. </div>
  55. </template>
  56. <template #table>
  57. <CzrTable
  58. v-loading="state.query.loading"
  59. v-model:data="state.query.result.data"
  60. :head="state.query.head"
  61. :total="state.query.result.total"
  62. :page="state.query.page.pageNum"
  63. :pageSize="state.query.page.pageSize"
  64. @handlePage="onPage"
  65. @handleSort="onSort"
  66. v-model:selected="state.query.selected"
  67. >
  68. <template #caozuo-column-value="{ scope }">
  69. <div class="__czr-table-operations">
  70. <CzrButton type="table" title="编辑" @click="onEdit(scope.row)" />
  71. <CzrButton type="table-del" @click="onDel(scope.row)" />
  72. </div>
  73. </template>
  74. </CzrTable>
  75. </template>
  76. </CzrContent>
  77. <detailCom
  78. v-model:show="state.detail.show"
  79. :transfer="state.detail.transfer"
  80. @refresh="onSearch"
  81. />
  82. </template>
  83. <script setup lang="ts">
  84. import {
  85. computed,
  86. getCurrentInstance,
  87. onMounted,
  88. reactive,
  89. ref,
  90. watch,
  91. } from 'vue'
  92. import { Search } from '@element-plus/icons-vue'
  93. import { debounce } from 'lodash'
  94. import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
  95. import { ElMessage } from 'element-plus'
  96. import detailCom from './detail.vue'
  97. import { tenantsDel, tenantsPage } from '@/api/modules/center/tenant'
  98. const AppStore = useAppStore()
  99. const DialogStore = useDialogStore()
  100. const DictionaryStore = useDictionaryStore()
  101. const emit = defineEmits([])
  102. const props = defineProps({})
  103. const { proxy }: any = getCurrentInstance()
  104. const state: any = reactive({
  105. text: '',
  106. query: {
  107. init: false,
  108. loading: false,
  109. head: [
  110. { value: 'name', label: '租户名称', show: true },
  111. { value: 'code', label: '租户编号', show: true },
  112. { value: 'userQuota', label: '用户配额', show: true },
  113. {
  114. value: 'enabled',
  115. label: '租户状态',
  116. show: true,
  117. dictList: computed(() => DictionaryStore.trueFalseStatus),
  118. },
  119. { value: 'userCounts', label: '用户数量', show: true, sort: true },
  120. {
  121. value: 'createTime',
  122. label: '租户启用时间',
  123. show: true,
  124. width: 180,
  125. datetime: true,
  126. sort: true,
  127. },
  128. {
  129. value: 'updateTime',
  130. label: '租户停用时间',
  131. show: true,
  132. width: 180,
  133. datetime: true,
  134. sort: true,
  135. },
  136. {
  137. value: 'caozuo',
  138. label: '操作',
  139. show: true,
  140. width: 200,
  141. fixed: 'right',
  142. popover: false,
  143. },
  144. ],
  145. page: {
  146. pageNum: 1,
  147. pageSize: 20,
  148. },
  149. form: {},
  150. formReal: {},
  151. sort: {},
  152. result: {
  153. total: 0,
  154. data: [],
  155. },
  156. selected: [],
  157. },
  158. detail: {
  159. show: false,
  160. transfer: {},
  161. },
  162. })
  163. const setText = debounce((v) => {
  164. state.query.form.keyword = v
  165. }, 1000)
  166. watch(
  167. () => state.text,
  168. (n) => {
  169. setText(n)
  170. },
  171. )
  172. watch(
  173. () => state.query.form,
  174. (n) => {
  175. if (state.query.init) {
  176. onSearch()
  177. }
  178. },
  179. { deep: true },
  180. )
  181. const onSort = ({ key, value }) => {
  182. state.query.sort[key] = value
  183. onSearch()
  184. }
  185. const onPage = (pageNum, pageSize) => {
  186. setTimeout(() => {
  187. state.query.init = true
  188. }, 100)
  189. state.query.page = {
  190. pageNum: pageNum,
  191. pageSize: pageSize,
  192. }
  193. const params = {
  194. page: state.query.page.pageNum,
  195. size: state.query.page.pageSize,
  196. }
  197. // 添加表单参数
  198. for (const [k, v] of Object.entries(state.query.formReal)) {
  199. if (proxy.$czrUtil.isValue(v)) {
  200. params[k] = v
  201. }
  202. }
  203. // 添加排序参数
  204. for (const [k, v] of Object.entries(state.query.sort)) {
  205. if (v) {
  206. params['sort'] = k
  207. params['direction'] = v
  208. }
  209. }
  210. state.query.loading = true
  211. tenantsPage(params)
  212. .then(({ data }: any) => {
  213. state.query.result.total = data.totalElements
  214. state.query.result.data = data.content
  215. })
  216. .catch(() => {})
  217. .finally(() => {
  218. state.query.loading = false
  219. })
  220. }
  221. const onSearch = () => {
  222. state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
  223. onPage(1, state.query.page.pageSize)
  224. }
  225. const onReset = () => {
  226. state.query.page = {
  227. pageNum: 1,
  228. pageSize: 20,
  229. }
  230. state.query.form = {}
  231. state.query.sort = {}
  232. onSearch()
  233. }
  234. const onAdd = () => {
  235. state.detail.transfer = {
  236. mode: 'add',
  237. }
  238. state.detail.show = true
  239. }
  240. const onEdit = (row) => {
  241. state.detail.transfer = {
  242. mode: 'edit',
  243. id: row.id,
  244. }
  245. state.detail.show = true
  246. }
  247. const onDel = (row: any) => {
  248. DialogStore.confirm({
  249. title: '删除确认',
  250. content: `请确认是否删除${row.name}?`,
  251. onSubmit: () => {
  252. tenantsDel(row.id)
  253. .then(() => {
  254. ElMessage.success('删除成功!')
  255. })
  256. .catch(() => {})
  257. .finally(() => {
  258. onSearch()
  259. })
  260. },
  261. })
  262. }
  263. onMounted(() => {
  264. initDictionary()
  265. onReset()
  266. })
  267. const initDictionary = () => {}
  268. </script>
  269. <style lang="scss" scoped></style>