index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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="softwareData.Filter" :inline="true" @submit.stop.prevent>
  8. <el-form-item prop="name" style="width: 100%">
  9. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  10. <el-form-item label="软件类型">
  11. <el-select v-model="softwareData.Filter.softwareType" placeholder="请选择软件类型" >
  12. <el-option v-for="(value, key) in softwareType" :key="key" :label="value[1].name" :value="Number(value[1].value)" />
  13. </el-select>
  14. </el-form-item>
  15. </el-col>
  16. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  17. <el-form-item label="软件名称">
  18. <el-input v-model="softwareData.Filter.softwareName" placeholder="单行输入" clearable></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  22. <el-form-item label="版本">
  23. <el-input v-model="softwareData.Filter.version" placeholder="单行输入" clearable></el-input>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  27. <el-form-item label="设备类型">
  28. <el-select v-model="softwareData.Filter.equipmentType" placeholder="请选择设备类型" >
  29. <el-option v-for="(value, key) in equipmentType" :key="key" :label="value[1].name" :value="Number(value[1].value)" />
  30. </el-select>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  34. <el-form-item label="选择时间">
  35. <el-date-picker
  36. v-model="softwareData.time"
  37. type="datetimerange"
  38. value-format="YYYY-MM-DD HH:mm:ss"
  39. range-separator="To"
  40. start-placeholder="Start date"
  41. end-placeholder="End date"
  42. />
  43. </el-form-item>
  44. </el-col>
  45. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  46. <el-form-item>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
  50. <el-form-item>
  51. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  52. <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
  53. </el-form-item>
  54. </el-col>
  55. </el-form-item>
  56. </el-form>
  57. <div class="my-flex my-flex-start" >
  58. <el-button type="primary" icon="ele-CirclePlus" @click="onAdd"> 上传软件包 </el-button>
  59. </div>
  60. </el-card>
  61. </el-col>
  62. <!--表格-->
  63. <el-col :xs="24" >
  64. <el-card style="height: 70vh" class="my-fill mt8" shadow="hover">
  65. <el-table v-loading="softwareData.loading" stripe :data="softwareData.tableModel" row-key="id" style="width: 100%">
  66. <el-table-column v-for="column in softwareData.dynamicColumns" :key="column.prop" :prop="column.prop" :label="column.label" >
  67. <template #default="{ row }">
  68. <span :style="getColor(column.prop,row)">
  69. {{getProp(column.prop,row)}}
  70. </span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="操作" fixed="right" header-align="center" align="center" class="right-operation" width="140">
  74. <template #default="{ row }" >
  75. <el-link
  76. class="my-el-link mr12 ml12"
  77. v-if="row.state === 0"
  78. type="primary"
  79. icon="ele-Upload"
  80. size="small"
  81. @click="onRelease(row)"
  82. :underline="false"
  83. target="_blank"
  84. >发布</el-link>
  85. <el-link
  86. class="my-el-link mr12 ml12"
  87. v-if="row.state === 0"
  88. type="primary"
  89. icon="ele-Edit"
  90. size="small"
  91. @click="editTableData(row)"
  92. :underline="false"
  93. target="_blank"
  94. >编辑</el-link>
  95. <el-link
  96. class="my-el-link mr12 ml12"
  97. v-if="row.state === 1"
  98. type="primary"
  99. icon="ele-Download"
  100. size="small"
  101. @click="onDownload(row)"
  102. :underline="false"
  103. target="_blank"
  104. >下载</el-link>
  105. <el-link
  106. class="my-el-link mr12 ml12"
  107. v-if="row.state === 1"
  108. type="primary"
  109. icon="ele-WarningFilled"
  110. size="small"
  111. @click="onFailure(row)"
  112. :underline="false"
  113. target="_blank"
  114. >失效</el-link>
  115. <el-link
  116. class="my-el-link mr12 ml12"
  117. v-if="row.state !== 0"
  118. type="primary"
  119. icon="ele-Tickets"
  120. size="small"
  121. @click="onDownloadRecord(row.guid)"
  122. :underline="false"
  123. target="_blank"
  124. >下载记录</el-link>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <div class="my-flex my-flex-end" style="margin-top: 20px">
  129. <el-pagination
  130. v-model:currentPage="softwareData.pageInput.CurrentPage"
  131. v-model:page-size="softwareData.pageInput.PageSize"
  132. :total="softwareData.total"
  133. :page-sizes="[10, 20, 50, 100]"
  134. small
  135. background
  136. @size-change="onSizeChange"
  137. @current-change="onCurrentChange"
  138. layout="total, sizes, prev, pager, next, jumper"
  139. />
  140. </div>
  141. <template>
  142. <a ref="downloadLink" style="display: none;"></a>
  143. </template>
  144. </el-card>
  145. </el-col>
  146. </el-row>
  147. <EditDialog ref="editDialogRef" />
  148. <DownloadDialog ref="downloadDialogRef" />
  149. </div>
  150. </template>
  151. <script setup lang="ts">
  152. import {defineAsyncComponent, onBeforeMount, onMounted, reactive, ref, watch} from "vue";
  153. import {useGlobalCacheStore} from "/@/stores/globalCacheStore";
  154. import {
  155. softwarePackageManagement_AllDto,
  156. softwarePackageManagement_SearchFilter,
  157. softwarePackageManagement_TableData
  158. } from "/@/api/admin/deviceAuthorization/softwarePackageManagementDto";
  159. import type {pageInput} from "/@/api/admin/shareDto/shareDto";
  160. import eventBus from "/@/utils/mitt";
  161. import {SoftwarePackageManagementApi} from "/@/api/admin/deviceAuthorization/softwarePackageManagementApi";
  162. import { storeToRefs } from 'pinia'
  163. import { useUserInfo } from '/@/stores/userInfo'
  164. /**引入组件*/
  165. const EditDialog = defineAsyncComponent(() => import('./components/form-edit.vue'))
  166. const DownloadDialog = defineAsyncComponent(() => import('./components/table-download.vue'))
  167. // import {pageInput} from "/@/api/admin/shareDto/shareDto";
  168. const editDialogRef = ref()
  169. const downloadDialogRef=ref()
  170. /**获取全局缓存*/
  171. const globalCacheStore = useGlobalCacheStore()
  172. /**设备类型缓存*/
  173. const equipmentType = ref(globalCacheStore.getGlobalStore().get('equipmentType'))
  174. /**软件类型缓存*/
  175. const softwareType = ref(globalCacheStore.getGlobalStore().get('softwareType'))
  176. /**软件包状态缓存*/
  177. const softwarePackageStatus = ref(globalCacheStore.getGlobalStore().get('softwarePackageStatus'))
  178. /**软件包管理对象*/
  179. const softwareData = reactive({
  180. time:'',
  181. /**加载显示 */
  182. loading: false,
  183. /**条件查询模块 */
  184. Filter: {
  185. /**软件类型 */
  186. softwareType: "",
  187. /**软件名称 */
  188. softwareName: "",
  189. /**版本 */
  190. version: "",
  191. /**设备类型*/
  192. equipmentType: "",
  193. /**开始的时间 */
  194. BeginTime: null,
  195. /**开始的时间 */
  196. EndTime: null,
  197. } as softwarePackageManagement_SearchFilter,
  198. /**表格信息 */
  199. tableModel: [] as softwarePackageManagement_TableData,
  200. /**动态表头 */
  201. dynamicColumns: [
  202. { prop: 'date', label: '日期' },
  203. { prop: 'softwareType', label: '软件类型' },
  204. { prop: 'equipmentType', label: '设备类型' },
  205. { prop: 'softwareName', label: '软件名称' },
  206. { prop: 'version', label: '版本号' },
  207. { prop: 'explain', label: '说明' },
  208. { prop: 'state', label: '状态' },
  209. { prop: 'numberOfDownloads', label: '下载次数' },
  210. { prop: 'remark', label: '备注' },
  211. { prop: 'releaseTime', label: '发布日期' },
  212. { prop: 'uploadTime', label: '上传日期' },
  213. ],
  214. /**分页标识 */
  215. pageInput:{
  216. CurrentPage: 1,
  217. PageSize: 10,
  218. } as pageInput,
  219. /**分页总数 */
  220. total: 0,
  221. } as softwarePackageManagement_AllDto)
  222. const downloadLink = ref()
  223. /**条件查询 */
  224. const onQuery = () => {
  225. init()
  226. }
  227. /**将Filter对象成.的连接方式*/
  228. const flattenObject = (obj, parentKey = '') => {
  229. const result = {};
  230. for (const key in obj) {
  231. if (obj.hasOwnProperty(key)) {
  232. const newKey = parentKey ? `${parentKey}.${key}` : key;
  233. if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
  234. const flattened = flattenObject(obj[key], newKey);
  235. Object.assign(result, flattened);
  236. } else {
  237. result[newKey] = obj[key];
  238. }
  239. }
  240. }
  241. return result;
  242. }
  243. /**初始化 */
  244. const init = async () => {
  245. softwareData.loading = true
  246. const query = flattenObject({ Filter: softwareData.Filter})
  247. debugger
  248. const res:any = await new SoftwarePackageManagementApi().getPageData({...softwareData.pageInput, Filter:softwareData.Filter})
  249. softwareData.tableModel = res?.data?.list ?? []
  250. softwareData.total = res?.data?.total ?? 0
  251. softwareData.loading = false
  252. }
  253. onMounted(() => {
  254. init()
  255. eventBus.off('refreshView')
  256. eventBus.on('refreshView', async () => {
  257. await init()
  258. })
  259. console.log()
  260. })
  261. onBeforeMount(() => {
  262. eventBus.off('refreshView')
  263. })
  264. /**
  265. * 监听时间变换
  266. */
  267. watch(() => softwareData.time, (newVal ) => {
  268. if(newVal.length === 0){
  269. return
  270. }
  271. softwareData.Filter.BeginTime = newVal?.[0].toString()
  272. softwareData.Filter.EndTime = newVal?.[1].toString()
  273. })
  274. /**重置查询条件 */
  275. const resetQuery = () => {
  276. softwareData.Filter.softwareType = ''
  277. softwareData.Filter.softwareName = ''
  278. softwareData.Filter.version = ''
  279. softwareData.Filter.equipmentType = ''
  280. softwareData.Filter.BeginTime = ''
  281. softwareData.Filter.EndTime = ''
  282. softwareData.time = ''
  283. softwareData.pageInput.CurrentPage = 1
  284. }
  285. /**重置 */
  286. const onReset = () => {
  287. resetQuery()
  288. init()
  289. }
  290. /**添加*/
  291. const onAdd = () => {
  292. editDialogRef.value.openDialog()
  293. }
  294. /**编辑弹窗 */
  295. const editTableData = (row) => {
  296. editDialogRef.value.openDialog(row)
  297. }
  298. /**发布*/
  299. const onRelease = (row) => {
  300. debugger
  301. //downloadUrl
  302. softwareData.loading = true;
  303. (row as softwarePackageManagement_TableData).state = 1
  304. var RowData = JSON.parse(JSON.stringify(row))
  305. var res = new SoftwarePackageManagementApi().addData(RowData as softwarePackageManagement_TableData)
  306. softwareData.loading = false
  307. }
  308. /**下载*/
  309. const onDownload = (row) => {
  310.   softwareData.loading = true;
  311.   var RowData =  JSON.parse(JSON.stringify(row))
  312.   const params = RowData as softwarePackageManagement_TableData
  313.   //const link = downloadLink.value;
  314.   //const url = `http://localhost:8000/api/app/software/download-file`;
  315.   //link.href = url;
  316.   //link.click();
  317.   const filename =  params.fileName?.toString();
  318.   const { userInfos } = storeToRefs(useUserInfo());
  319.   const accessToken = userInfos.value.token
  320.   const token = `Bearer ${accessToken}`
  321.   var myHeaders = new Headers();
  322. myHeaders.append("Authorization", token);
  323. const requestOptions: RequestInit = {
  324.   method: 'GET',
  325.   headers: myHeaders,
  326.   redirect: 'follow', // 此处使用枚举值 'follow'
  327. };
  328.   /* var res =  new SoftwarePackageManagementApi().DownloadFile(row as softwarePackageManagement_TableData) */
  329.   const fileUrl = import.meta.env.VITE_API_URL +'/api/app/software/download-file?guid='+params.guid; // 替换为实际文件URL
  330.                     fetch(fileUrl,requestOptions)
  331.                         .then(response => response.blob())
  332.                         .then(blob => {
  333.                             const link = document.createElement('a');
  334.                             link.href = URL.createObjectURL(blob);
  335.                             link.download = filename;
  336.                             link.click();
  337.                             softwareData.loading = false
  338.                         })
  339.                         .catch(error => {
  340.                             console.error('下载失败:', error);
  341.                             softwareData.loading = false
  342.                         });
  343.  // var res =  new SoftwarePackageManagementApi().DownloadFile(RowData as softwarePackageManagement_TableData)
  344.  
  345. }
  346. /**失效*/
  347. const onFailure = (row) => {
  348. softwareData.loading = true;
  349. (row as softwarePackageManagement_TableData).state = 2
  350. var RowData = JSON.parse(JSON.stringify(row))
  351. var res = new SoftwarePackageManagementApi().addData(RowData as softwarePackageManagement_TableData)
  352. softwareData.loading = false
  353. }
  354. /**下载记录*/
  355. const onDownloadRecord = (id) => {
  356. downloadDialogRef.value.openDialog(id)
  357. //alert('下载记录')
  358. }
  359. /**页条数变化*/
  360. const onSizeChange = () => {
  361. init()
  362. }
  363. /**页数变化*/
  364. const onCurrentChange = () =>{
  365. init()
  366. }
  367. /**过滤数字的属性*/
  368. const getProp = (val,row) => {
  369. if(val === 'softwareType') return softwareType.value.get(String(row[val])).name
  370. if(val === 'equipmentType') return equipmentType.value.get(String(row[val])).name
  371. if(val === 'state') return softwarePackageStatus.value.get(String(row[val])).name
  372. return row[val]
  373. }
  374. const getColor = (val,row) => {
  375. if(val === 'state') {
  376. const code = softwarePackageStatus.value.get(String(row[val])).code.split('_')
  377. return {color:code[1]}
  378. }
  379. return {}
  380. }
  381. </script>
  382. <style scoped lang="scss">
  383. .el-link{
  384. padding: 5px;
  385. }
  386. </style>