index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div :class="prefixCls" class="m-5 bg-white">
  3. <div class="flex flex-nowrap w-full h-full">
  4. <div class="w-1/4 border-gray-400 border">
  5. <header class="p-2 flex justify-between items-center h-12">
  6. <div class="w-1/2">
  7. <BasicUpload
  8. v-show="showUploadBtn"
  9. :max-size="20"
  10. :max-number="1"
  11. @change="handleChange"
  12. :api="uploadApi"
  13. :showPreviewNumber="false"
  14. :emptyHidePreview="true"
  15. :accept="['xlsx', 'xls', 'pdf']"
  16. />
  17. </div>
  18. <div class="flex flex-row w-1/2 justify-end">
  19. <span class="flex align-middle cursor-pointer" @click="handleTreeOpreate('upSerial')">
  20. <Icon icon="mdi:arrow-up" :size="18" />
  21. 上移
  22. </span>
  23. <span
  24. class="flex align-middle ml-1 cursor-pointer"
  25. @click="handleTreeOpreate('downSerial')"
  26. >
  27. <Icon icon="mdi:arrow-down" :size="18" />
  28. 下移
  29. </span>
  30. </div>
  31. </header>
  32. <section>
  33. <BasicTree
  34. v-if="treeData.length"
  35. :tree-data="treeData"
  36. :replace-fields="replaceFields"
  37. :show-line="true"
  38. :defaultExpandAll="true"
  39. @select="onSelect"
  40. />
  41. </section>
  42. </div>
  43. <div class="w-3/4 ml-4 flex flex-col">
  44. <header class="h-1/12 mt-2 flex justify-between items-center">
  45. <span class="text-3xl font-bold">{{ detail.name }}</span>
  46. <section>
  47. <AButton
  48. v-show="showExcel"
  49. type="primary"
  50. size="small"
  51. class="mr-4"
  52. @click="uploadExecl"
  53. >下载Excel</AButton
  54. >
  55. <!-- <AButton type="primary" size="small" class="mx-1">下载PDF</AButton> -->
  56. <!-- <AButton type="primary" size="small" class="mx-1">编辑</AButton> -->
  57. <!-- <span class="h-full border-l-1 border-gray-400 mx-1"></span> -->
  58. <!-- <AButton type="primary" size="small" class="mx-1 mr-4">下载</AButton> -->
  59. </section>
  60. </header>
  61. <section class="h-11/12 border-gray-400 border">
  62. <!-- <PreviewPdf v-show="!showExcel" :url="pdfUrl"></PreviewPdf> -->
  63. </section>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <script lang="ts">
  69. import { computed, defineComponent, ref, watch } from 'vue'
  70. import { saveSectionFileApi, sectionAllApi, treeDetailApi, treeResfulApi } from '/@/api/sys/tree'
  71. import { useDesign } from '/@/hooks/web/useDesign'
  72. import { BasicTree } from '/@/components/Tree/index'
  73. import { Icon } from '/@/components/Icon'
  74. import { message } from 'ant-design-vue'
  75. import { TreeResultModel } from '/@/api/model/tree'
  76. import { BasicUpload } from '/@/components/Upload'
  77. import { uploadApi } from '/@/api/sys/upload'
  78. import { TreeRow } from '/#/tree'
  79. import { downloadByUrl } from '/@/utils/file/download'
  80. import PreviewPdf from './pdf.vue'
  81. interface ATreeRow extends TreeRow {
  82. showUpload: boolean
  83. }
  84. export default defineComponent({
  85. name: 'Catalog',
  86. components: { BasicTree, Icon, BasicUpload, PreviewPdf },
  87. setup() {
  88. const treeData = ref<TreeResultModel[]>([])
  89. const row = ref<ATreeRow>({
  90. id: '',
  91. parentId: '',
  92. name: '',
  93. depth: 0,
  94. serial: 0,
  95. attribution: '',
  96. code: '',
  97. contractId: '',
  98. createTime: '',
  99. showUpload: false
  100. })
  101. const detail = ref({ name: '', content: '', filepath: '', filename: '', ext: '', fid: '' })
  102. async function initData() {
  103. const result = await sectionAllApi()
  104. treeData.value = result.children
  105. }
  106. async function initSectionDetail(id: string) {
  107. const result = await treeDetailApi(id)
  108. detail.value = result
  109. }
  110. initData()
  111. const handleTreeOpreate = async (operation: 'upSerial' | 'downSerial') => {
  112. const id = row.value.id
  113. if (!id) {
  114. return message.error('请先选中节点')
  115. }
  116. await treeResfulApi({ id, type: 'serial', operation })
  117. await initData()
  118. }
  119. const { prefixCls } = useDesign('catalog')
  120. const replaceFields = { children: 'children', title: 'name', key: 'id' }
  121. const onSelect = (selectedKeys: Event, { selectedNodes }) => {
  122. if (selectedKeys.length) {
  123. const {
  124. id,
  125. parentId,
  126. name,
  127. depth,
  128. serial,
  129. attribution,
  130. code,
  131. contractId,
  132. children,
  133. createTime
  134. } = selectedNodes[0]?.props
  135. row.value = {
  136. showUpload: children && children.length ? false : true,
  137. id,
  138. parentId,
  139. name,
  140. depth,
  141. serial,
  142. attribution,
  143. code,
  144. contractId,
  145. createTime
  146. }
  147. }
  148. }
  149. watch(row, (row, prevRow) => {
  150. if (row.id !== prevRow.id) {
  151. initSectionDetail(row.id)
  152. }
  153. })
  154. const handleChange = async (list: string[]) => {
  155. await saveSectionFileApi({ id: row.value.id, contractId: list[0] })
  156. await initSectionDetail(row.value.id)
  157. }
  158. const showUploadBtn = computed(() => row.value.showUpload)
  159. const showExcel = computed(() => /.(excel)|(xls)|(xlsl)$/.test(detail.value.ext))
  160. const uploadExecl = () => {
  161. downloadByUrl({
  162. url: 'http://localhost:7070' + detail.value.filepath
  163. })
  164. }
  165. const pdfUrl = computed(() => 'http://localhost:7070' + detail.value.filepath)
  166. return {
  167. treeData,
  168. replaceFields,
  169. prefixCls,
  170. onSelect,
  171. handleTreeOpreate,
  172. detail,
  173. uploadApi,
  174. handleChange,
  175. row,
  176. showUploadBtn,
  177. showExcel,
  178. uploadExecl,
  179. pdfUrl
  180. }
  181. }
  182. })
  183. </script>
  184. <style lang="less" scoped>
  185. @prefix-cls: ~'@{namespace}-catalog';
  186. .@{prefix-cls} {
  187. width: calc(100% - 2.5rem);
  188. height: calc(100% - 2.5rem);
  189. overflow: hidden;
  190. }
  191. </style>