index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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.tenantStatus"
  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 { 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. { value: 'enabled', label: '租户状态', show: true },
  114. { value: 'name', label: '用户数量', show: true, sort: true },
  115. {
  116. value: 'createTime',
  117. label: '租户启用时间',
  118. show: true,
  119. width: 180,
  120. datetime: true,
  121. sort: true,
  122. },
  123. {
  124. value: 'updateTime',
  125. label: '租户停用时间',
  126. show: true,
  127. width: 180,
  128. datetime: true,
  129. sort: true,
  130. },
  131. {
  132. value: 'caozuo',
  133. label: '操作',
  134. show: true,
  135. width: 200,
  136. fixed: 'right',
  137. popover: false,
  138. },
  139. ],
  140. page: {
  141. pageNum: 1,
  142. pageSize: 20,
  143. },
  144. form: {},
  145. formReal: {},
  146. sort: {},
  147. result: {
  148. total: 0,
  149. data: [],
  150. },
  151. selected: [],
  152. },
  153. detail: {
  154. show: false,
  155. transfer: {},
  156. },
  157. })
  158. const setText = debounce((v) => {
  159. state.query.form.keyword = v
  160. }, 1000)
  161. watch(
  162. () => state.text,
  163. (n) => {
  164. setText(n)
  165. },
  166. )
  167. watch(
  168. () => state.query.form,
  169. (n) => {
  170. if (state.query.init) {
  171. onSearch()
  172. }
  173. },
  174. { deep: true },
  175. )
  176. const onSort = ({ key, value }) => {
  177. state.query.sort[key] = value
  178. onSearch()
  179. }
  180. const onPage = (pageNum, pageSize) => {
  181. setTimeout(() => {
  182. state.query.init = true
  183. }, 100)
  184. state.query.page = {
  185. pageNum: pageNum,
  186. pageSize: pageSize,
  187. }
  188. const params = {
  189. page: state.query.page.pageNum,
  190. size: state.query.page.pageSize,
  191. }
  192. // 添加表单参数
  193. for (const [k, v] of Object.entries(state.query.formReal)) {
  194. if (proxy.$czrUtil.isValue(v)) {
  195. params[k] = v
  196. }
  197. }
  198. // 添加排序参数
  199. for (const [k, v] of Object.entries(state.query.sort)) {
  200. }
  201. state.query.loading = true
  202. tenantsPage(params)
  203. .then(({ data }: any) => {
  204. state.query.result.total = data.totalElements
  205. state.query.result.data = data.content
  206. })
  207. .catch(() => {})
  208. .finally(() => {
  209. state.query.loading = false
  210. })
  211. }
  212. const onSearch = () => {
  213. state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
  214. onPage(1, state.query.page.pageSize)
  215. }
  216. const onReset = () => {
  217. state.query.page = {
  218. pageNum: 1,
  219. pageSize: 20,
  220. }
  221. state.query.form = {}
  222. state.query.sort = {}
  223. onSearch()
  224. }
  225. const onAdd = () => {
  226. state.detail.transfer = {
  227. mode: 'add',
  228. }
  229. state.detail.show = true
  230. }
  231. const onEdit = (row) => {
  232. state.detail.transfer = {
  233. mode: 'edit',
  234. id: row.id,
  235. }
  236. state.detail.show = true
  237. }
  238. const onDel = (row: any) => {
  239. DialogStore.confirm({
  240. title: '删除确认',
  241. content: `请确认是否删除`,
  242. onSubmit: () => {
  243. // appDel(row.id)
  244. // .then(() => {
  245. // ElMessage.success('删除成功!')
  246. // })
  247. // .catch(() => {})
  248. // .finally(() => {
  249. // onSearch()
  250. // })
  251. },
  252. })
  253. }
  254. onMounted(() => {
  255. initDictionary()
  256. onReset()
  257. })
  258. const initDictionary = () => {}
  259. </script>
  260. <style lang="scss" scoped>
  261. .model {
  262. width: 100%;
  263. background-image: url('@/assets/images/model/model-icon-7.png');
  264. background-repeat: no-repeat;
  265. background-size: 100% 100%;
  266. padding: 1rem;
  267. border-radius: 10px;
  268. box-shadow: 0rem 0.25rem 0.63rem 0rem rgba(40, 83, 247, 0.05);
  269. border: var(--czr-border);
  270. display: flex;
  271. flex-direction: column;
  272. }
  273. </style>