index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="layout-pd">
  3. <el-row>
  4. <!-- 操作 -->
  5. <el-col :xs="24">
  6. <el-card class="mt8" shadow="hover">
  7. <el-form :model="qrBookData.Filter" @submit.stop.prevent>
  8. <el-form-item prop="name" style="width: 100%;">
  9. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  10. <el-form-item label="上传人">
  11. <el-input v-model="qrBookData.Filter.Author" placeholder="单行输入"
  12. clearable></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  16. <el-form-item label="文件名">
  17. <el-input v-model="qrBookData.Filter.FileName" placeholder="单行输入"
  18. clearable></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  22. <el-form-item label="状态">
  23. <el-select placeholder="请选择上传状态">
  24. <el-option label="所有" :value="''"></el-option>
  25. <el-option label="开启" :value="''"></el-option>
  26. <el-option label="关闭" :value="''"></el-option>
  27. </el-select>
  28. </el-form-item>
  29. </el-col>
  30. </el-form-item>
  31. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  32. <el-form-item label="选择时间">
  33. <el-date-picker v-model="qrBookData.time" type="datetimerange"
  34. value-format="YYYY-MM-DD HH:mm:ss" range-separator="To"
  35. start-placeholder="开始日期" end-placeholder="结束日期" />
  36. </el-form-item>
  37. </el-col>
  38. </el-form>
  39. <hr>
  40. <!-- 按钮 -->
  41. <el-row justify="space-between" class="submit-button">
  42. <el-row>
  43. <el-button type="primary" icon="ele-Search" @click="getData()">查询</el-button>
  44. <el-button type="primary" plain icon="ele-RefreshRight" @click="clear()">清空</el-button>
  45. </el-row>
  46. <el-row>
  47. <el-button type="primary" icon="ele-CirclePlus" @click="uploadDialog">上传说明书</el-button>
  48. </el-row>
  49. </el-row>
  50. </el-card>
  51. </el-col>
  52. <!-- 表格 -->
  53. <el-col :xs="24">
  54. <el-card class="my-fill mt8" shadow="hover">
  55. <el-table v-loading="qrBookData.loading" stripe :data="qrBookData.tableModel" row-key="id"
  56. style="width: 100%;">
  57. <el-table-column
  58. v-for="column in qrBookData.dynamicColumns"
  59. :key="column.prop"
  60. :prop="column.prop"
  61. :label="column.label">
  62. <template #default="{ row }">
  63. <!-- 如果是状态列,使用 StatusBox 组件 -->
  64. <StatusBox
  65. v-if="column.prop === 'status'"
  66. :status="getStatusInfo(row[column.prop]).name" />
  67. <!-- 其他列保持原有逻辑 -->
  68. <span
  69. v-else
  70. :style="getColor(column.prop, row)">
  71. {{ getName(column.prop, row) }}
  72. </span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="操作" fixed="right" align="center" header-align="center"
  76. class="right-operation" width="140">
  77. <template #default="{ row }">
  78. <el-link class="my-el-link mr12 ml12" type="primary" :underline="false" target="_blank"
  79. icon="ele-Edit" @click="editDialog(row)">编辑</el-link>
  80. <el-link class="my-el-link mr12 ml12" type="primary" :underline="false" target="_blank"
  81. icon="ele-Download" @click="download(row, 0)">下载文件</el-link>
  82. <el-link class="my-el-link mr12 ml12" type="primary" :underline="false" target="_blank"
  83. icon="ele-Download" @click="download(row, 1)">下载二维码</el-link>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <div class="my-flex my-flex-end" style="margin-top: 20px">
  88. <el-pagination v-model:currentPage="qrBookData.PageInput.CurrentPage"
  89. v-model:page-size="qrBookData.PageInput.PageSize" :total="qrBookData.total"
  90. :page-sizes="[10, 15, 20, 50, 100]" small background @size-change="onSizeChange"
  91. @current-change="onCurrentChange" layout="total, sizes, prev, pager, next, jumper" />
  92. </div>
  93. <template>
  94. <a ref="downloadLink" style="display: none;"></a>
  95. </template>
  96. </el-card>
  97. </el-col>
  98. </el-row>
  99. <FileEditDialog ref="fileEditRef"></FileEditDialog>
  100. </div>
  101. </template>
  102. <script setup lang="ts">
  103. import { defineAsyncComponent, onBeforeMount, onMounted, reactive, ref, watch } from "vue";
  104. import { QRBookFilter, QRBookPageSearchResponse } from "/@/api/admin/productionManagement/QRBookDto";
  105. import { pageInput } from "/@/api/admin/shareDto/shareDto";
  106. import { QRBookApi } from "/@/api/admin/productionManagement/qrBookApi";
  107. import eventBus from "/@/utils/mitt";
  108. import { useGlobalCacheStore } from "/@/stores/globalCacheStore";
  109. import StatusBox from "/@/components/StatusBox.vue";
  110. /**引入组件*/
  111. const FileEditDialog = defineAsyncComponent(() => import('./components/qrbook-edit.vue'))
  112. const fileEditRef = ref()
  113. /** 获取全局缓存 */
  114. const globalCacheStore = useGlobalCacheStore()
  115. /** 获取文件状态 */
  116. const statusType = ref(globalCacheStore.getGlobalStore().get('qrBookFileStatus'))
  117. const downloadLink = ref()
  118. const qrBookData = reactive({
  119. // 是否加载
  120. loading: false,
  121. time: '',
  122. // 查询条件
  123. Filter: {
  124. Author: "",
  125. FileName: "",
  126. StartTime: null,
  127. EndTime: null
  128. } as QRBookFilter,
  129. // 表数据
  130. tableModel: [] as QRBookPageSearchResponse[],
  131. // 表头
  132. dynamicColumns: [
  133. { prop: 'fileName', label: '说明书文件名' },
  134. { prop: 'author', label: '上传人' },
  135. { prop: 'status', label: '状态' },
  136. { prop: 'uploadTime', label: '上传时间' },
  137. { prop: 'updateTime', label: '修改时间' },
  138. { prop: 'remark', label: '备注' }
  139. ],
  140. /**分页标识 */
  141. PageInput: {
  142. CurrentPage: 1,
  143. PageSize: 15,
  144. } as pageInput,
  145. /**分页总数 */
  146. total: 0
  147. })
  148. //获取数据
  149. const getData = async () => {
  150. qrBookData.loading = true
  151. let res = await new QRBookApi().getPage({
  152. ...qrBookData.PageInput,
  153. "Filter.Author": qrBookData.Filter.Author,
  154. "Filter.FileName": qrBookData.Filter.FileName,
  155. "Filter.StartTime": qrBookData.Filter.StartTime,
  156. "Filter.EndTime": qrBookData.Filter.EndTime
  157. })
  158. qrBookData.tableModel = res?.data?.list ?? []
  159. qrBookData.total = res?.data?.total ?? 0
  160. qrBookData.loading = false
  161. }
  162. //清除查询条件
  163. const clear = () => {
  164. qrBookData.Filter = {
  165. author: "",
  166. fileName: "",
  167. startTime: null,
  168. endTime: null
  169. } as QRBookFilter
  170. }
  171. //下载
  172. const download = async (row, type) => {
  173. let fileName = ""
  174. switch (type) {
  175. case 0:
  176. fileName = removeExtension(row.fileName) + row.extension
  177. break
  178. case 1:
  179. fileName = removeExtension(row.fileName) + ".PNG"
  180. break
  181. }
  182. let res = await new QRBookApi().donwloadFile(row.id, type, fileName)
  183. }
  184. //去除文件名后缀
  185. const removeExtension = (filename: string) => {
  186. const dotIndex = filename.lastIndexOf('.');
  187. if (dotIndex < 0) {
  188. // 如果没有找到'.',则返回原始文件名
  189. return filename;
  190. }
  191. // 返回去除最后一个'.'及其之后的所有字符的字符串
  192. return filename.slice(0, dotIndex);
  193. }
  194. //打开上传文件弹窗
  195. const uploadDialog = () => {
  196. fileEditRef.value.openDialog()
  197. }
  198. //打开编辑文件弹窗
  199. const editDialog = (row) => {
  200. fileEditRef.value.openDialog(row)
  201. }
  202. const onSizeChange = () => {
  203. getData()
  204. }
  205. const onCurrentChange = () => {
  206. getData()
  207. }
  208. //获取颜色值
  209. const getColor = (val, row) => {
  210. if (val === "status") return { color: statusType.value.get(String(row[val])).color }
  211. return {}
  212. }
  213. //获取名称值
  214. const getName = (val, row) => {
  215. if (val === "status") return statusType.value.get(String(row[val])).name
  216. return row[val]
  217. }
  218. watch(() => qrBookData.time, (val) => {
  219. if (val?.length === 0) return
  220. qrBookData.Filter.StartTime = val?.[0].toString()
  221. qrBookData.Filter.EndTime = val?.[1].toString()
  222. })
  223. onMounted(() => {
  224. getData()
  225. eventBus.off('refreshView')
  226. eventBus.on('refreshView', async () => {
  227. await getData()
  228. })
  229. })
  230. onBeforeMount(() => {
  231. eventBus.off('refreshView')
  232. })
  233. // 状态映射表
  234. const statusMap = {
  235. "0": { name: "关闭", color: "#F56C6C" }, // 红色表示关闭
  236. "1": { name: "开启", color: "#67C23A" }, // 绿色表示开启
  237. };
  238. // 根据 status 值获取映射后的对象
  239. const getStatusInfo = (status: string) => {
  240. return statusMap[status] || { name: "未知状态", color: "#000" };
  241. };
  242. </script>
  243. <style scoped lang="scss">
  244. .el-input,
  245. .el-select {
  246. width: 240px;
  247. }
  248. /* 输入框标签固定四个字符宽度 */
  249. ::v-deep .el-form-item__label {
  250. // 字体大小14,4个字符,12px右间距
  251. width: 14*4px+12px;
  252. justify-content: start;
  253. }
  254. /* 数据表头 设置灰色样式 */
  255. ::v-deep .el-table th.el-table__cell {
  256. background-color: #F6F6F6;
  257. }
  258. </style>