index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <script setup lang="ts">
  2. import { List, Card, Button, PaginationProps, Tooltip } from 'ant-design-vue';
  3. import { ReloadOutlined } from '@ant-design/icons-vue';
  4. import { onMounted, reactive, ref, unref } from 'vue';
  5. import { OrganizationIdTree, useResetOrganizationTree } from '../common/organizationIdTree';
  6. import { deleteBigScreenenter, getPage } from '/@/api/bigscreen/center/bigscreenCenter';
  7. import { BigScreenCenterItemsModel } from '/@/api/bigscreen/center/model/bigscreenCenterModel';
  8. import { PageWrapper } from '/@/components/Page';
  9. import { BasicForm, useForm } from '/@/components/Form';
  10. import { ConfigurationPermission, searchFormSchema } from './config';
  11. import { useMessage } from '/@/hooks/web/useMessage';
  12. import { Authority } from '/@/components/Authority';
  13. import ConfigurationCenterDrawer from './BigScreenDrawer.vue';
  14. import { useDrawer } from '/@/components/Drawer';
  15. import { getBoundingClientRect } from '/@/utils/domUtils';
  16. import configurationSrc from '/@/assets/icons/configuration.svg';
  17. import { cloneDeep } from 'lodash';
  18. import { useGlobSetting } from '/@/hooks/setting';
  19. import { AuthIcon, CardLayoutButton } from '/@/components/Widget';
  20. import AuthDropDown from '/@/components/Widget/AuthDropDown.vue';
  21. const listColumn = ref(5);
  22. const { createMessage } = useMessage();
  23. const organizationId = ref<Nullable<number>>(null);
  24. const pagination = reactive<PaginationProps>({
  25. size: 'small',
  26. showTotal: (total: number) => `共 ${total} 条数据`,
  27. current: 1,
  28. pageSize: unref(listColumn) * 2,
  29. onChange: (page: number) => {
  30. pagination.current = page;
  31. getListData();
  32. },
  33. });
  34. const loading = ref(false);
  35. const dataSource = ref<BigScreenCenterItemsModel[]>([]);
  36. const [registerForm, { getFieldsValue }] = useForm({
  37. schemas: searchFormSchema,
  38. showAdvancedButton: true,
  39. labelWidth: 100,
  40. compact: true,
  41. resetFunc: () => {
  42. resetFn();
  43. organizationId.value = null;
  44. return getListData();
  45. },
  46. submitFunc: async () => {
  47. const value = getFieldsValue();
  48. getListData(value);
  49. },
  50. });
  51. async function getListData(value: Recordable = {}) {
  52. try {
  53. loading.value = true;
  54. const pageSize = unref(listColumn) * 2;
  55. const { items, total } = await getPage({
  56. organizationId: unref(organizationId),
  57. ...value,
  58. page: pagination.current!,
  59. pageSize,
  60. });
  61. dataSource.value = items;
  62. Object.assign(pagination, { total, pageSize });
  63. } catch (error) {
  64. } finally {
  65. loading.value = false;
  66. }
  67. }
  68. onMounted(() => {
  69. getListData();
  70. });
  71. const searchInfo = reactive<Recordable>({});
  72. const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo);
  73. const handleSelect = (orgId: number) => {
  74. organizationId.value = orgId;
  75. getListData();
  76. };
  77. const [registerDrawer, { openDrawer }] = useDrawer();
  78. const handleCreateOrUpdate = (record?: BigScreenCenterItemsModel) => {
  79. if (record) {
  80. openDrawer(true, {
  81. isUpdate: true,
  82. record: cloneDeep(record),
  83. });
  84. } else {
  85. openDrawer(true, {
  86. isUpdate: false,
  87. });
  88. }
  89. };
  90. const { largeDesignerPrefix } = useGlobSetting();
  91. const handlePreview = (record: BigScreenCenterItemsModel) => {
  92. window.open(`${largeDesignerPrefix}/#/chart/preview/${record.id}`);
  93. };
  94. const handleDesign = (record: BigScreenCenterItemsModel) => {
  95. window.open(`${largeDesignerPrefix}/#/chart/home/${record.id}`);
  96. };
  97. const handleDelete = async (record: BigScreenCenterItemsModel) => {
  98. try {
  99. await deleteBigScreenenter([record.id]);
  100. createMessage.success('删除成功');
  101. await getListData();
  102. } catch (error) {}
  103. };
  104. const handleCardLayoutChange = () => {
  105. pagination.current = 1;
  106. getListData();
  107. };
  108. const listEl = ref<Nullable<ComponentElRef>>(null);
  109. onMounted(() => {
  110. const clientHeight = document.documentElement.clientHeight;
  111. const rect = getBoundingClientRect(unref(listEl)!.$el!) as DOMRect;
  112. // margin-top 24 height 24
  113. const paginationHeight = 24 + 24 + 8;
  114. // list pading top 8 maring-top 8 extra slot 56
  115. const listContainerMarginBottom = 8 + 8 + 56;
  116. const listContainerHeight =
  117. clientHeight - rect.top - paginationHeight - listContainerMarginBottom;
  118. const listContainerEl = (unref(listEl)!.$el as HTMLElement).querySelector(
  119. '.ant-spin-container'
  120. ) as HTMLElement;
  121. listContainerEl &&
  122. (listContainerEl.style.height = listContainerHeight + 'px') &&
  123. (listContainerEl.style.overflowY = 'auto') &&
  124. (listContainerEl.style.overflowX = 'hidden');
  125. });
  126. </script>
  127. <template>
  128. <PageWrapper dense contentFullHeight contentClass="flex">
  129. <OrganizationIdTree @select="handleSelect" ref="organizationIdTreeRef" />
  130. <section class="flex-auto p-4 w-3/4 xl:w-4/5 w-full configuration-list">
  131. <div class="flex-auto w-full bg-light-50 dark:bg-dark-900 p-4">
  132. <BasicForm @register="registerForm" />
  133. </div>
  134. <List
  135. ref="listEl"
  136. :loading="loading"
  137. class="flex-auto bg-light-50 dark:bg-dark-900 !p-2 !mt-4"
  138. position="bottom"
  139. :pagination="pagination"
  140. :data-source="dataSource"
  141. :grid="{ gutter: 4, column: listColumn }"
  142. >
  143. <template #header>
  144. <div class="flex gap-3 justify-end">
  145. <Authority :value="ConfigurationPermission.CREATE">
  146. <Button type="primary" @click="handleCreateOrUpdate()">新增大屏</Button>
  147. </Authority>
  148. <CardLayoutButton v-model:value="listColumn" @change="handleCardLayoutChange" />
  149. <Tooltip title="刷新">
  150. <Button type="primary" @click="getListData">
  151. <ReloadOutlined />
  152. </Button>
  153. </Tooltip>
  154. </div>
  155. </template>
  156. <template #renderItem="{ item }">
  157. <List.Item>
  158. <Card>
  159. <template #cover>
  160. <div class="h-full w-full hover-show-modal-content">
  161. <img
  162. style="position: relative"
  163. class="w-full h-45 hover-show-modal"
  164. alt="example"
  165. :src="item.thumbnail || configurationSrc"
  166. @click="handlePreview(item)"
  167. />
  168. <div class="masker-content">
  169. <div class="masker-text">
  170. <div
  171. ><span>{{ item.name }}</span></div
  172. >
  173. <div>
  174. <span class="masker-text-org"
  175. >所属组织:{{ item.organizationDTO.name }}</span
  176. >
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </template>
  182. <template class="ant-card-actions" #actions>
  183. <Tooltip title="预览">
  184. <AuthIcon
  185. class="!text-lg"
  186. icon="ant-design:eye-outlined"
  187. @click="handlePreview(item)"
  188. />
  189. </Tooltip>
  190. <Tooltip title="设计">
  191. <AuthIcon
  192. class="!text-lg"
  193. icon="ant-design:edit-outlined"
  194. @click="handleDesign(item)"
  195. />
  196. </Tooltip>
  197. <AuthDropDown
  198. :dropMenuList="[
  199. {
  200. text: '编辑',
  201. auth: ConfigurationPermission.UPDATE,
  202. icon: 'clarity:note-edit-line',
  203. event: '',
  204. onClick: handleCreateOrUpdate.bind(null, item),
  205. },
  206. {
  207. text: '删除',
  208. auth: ConfigurationPermission.DELETE,
  209. icon: 'ant-design:delete-outlined',
  210. event: '',
  211. popconfirm: {
  212. title: '是否确认删除操作?',
  213. onConfirm: handleDelete.bind(null, item),
  214. },
  215. },
  216. ]"
  217. :trigger="['hover']"
  218. />
  219. </template>
  220. </Card>
  221. </List.Item>
  222. </template>
  223. </List>
  224. </section>
  225. <ConfigurationCenterDrawer @register="registerDrawer" @success="getListData" />
  226. </PageWrapper>
  227. </template>
  228. <style lang="less" scoped>
  229. .configuration-list:deep(.ant-list-header) {
  230. border-bottom: none !important;
  231. }
  232. .configuration-list:deep(.ant-list-pagination) {
  233. height: 24px;
  234. }
  235. .configuration-list:deep(.ant-card-body) {
  236. padding: 16px !important;
  237. }
  238. .configuration-list:deep(.ant-list-empty-text) {
  239. @apply w-full h-full flex justify-center items-center;
  240. }
  241. :deep(.ant-card-body) {
  242. display: none;
  243. }
  244. .masker-content {
  245. opacity: 0;
  246. z-index: 1000;
  247. width: 100%;
  248. height: 11.25rem;
  249. background-color: rgba(0, 0, 0, 0.5);
  250. position: absolute;
  251. transition: opacity 0.5;
  252. pointer-events: none;
  253. top: 0;
  254. left: 0;
  255. right: 0;
  256. bottom: 0;
  257. .masker-text {
  258. color: #fff;
  259. font-size: 16px;
  260. display: flex;
  261. flex-direction: column;
  262. align-items: center;
  263. justify-content: center;
  264. line-height: 2.5rem;
  265. margin: 4rem 0;
  266. .masker-text-org {
  267. font-size: 12px;
  268. position: absolute;
  269. bottom: 0;
  270. left: 0.8rem;
  271. }
  272. }
  273. }
  274. .hover-show-modal-content:hover > .masker-content {
  275. opacity: 1;
  276. }
  277. </style>