SoftwareDetail.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="software-detail" v-loading="loading">
  3. <div class="pt-3" style="padding-left: 2.5%">
  4. <div class="media">
  5. <img class="mr-3" :src="items.src" width="50" height="50" :alt="items.title">
  6. <div class="media-body">
  7. <h5 class="mt-0 mb-1">{{ items.title }}</h5>
  8. {{ items.productName }}
  9. </div>
  10. </div>
  11. </div>
  12. <div class="pt-3">
  13. <el-tabs v-model="activeName" type="card" @tab-click="checkOnline">
  14. <el-tab-pane class="pl-3 software-content" name="first">
  15. <span slot="label" class="detail-title"><span class="iconbg iconbg-purple rounded"><i class="fas fa-download"></i></span>下载软件</span>
  16. <div class="details" v-for="down in downlist">
  17. <div class="float-right">
  18. <button @click="downloadSoftware(down.down_id, down.version)" class="btn btn-white btn-sm"><i class="fas fa-download mr-2"></i>下载</button>
  19. </div>
  20. <h5 class="w-25 d-inline-block">{{ down.title }}</h5>
  21. <div class="w-50 d-inline-block"><span v-if="down.key_number !== ''">锁号:{{ down.key_number }}</span></div>
  22. </div>
  23. </el-tab-pane>
  24. <el-tab-pane class="pl-3 software-content" name="second" v-html="items.content">
  25. <span slot="label" class="detail-title"><span class="iconbg iconbg-green rounded"><i class="fas fa-info"></i></span>软件详情</span>
  26. </el-tab-pane>
  27. </el-tabs>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import mixin from '../mixin'
  33. const fs = require('fs-extra')
  34. const path = require('path')
  35. export default {
  36. mixins: [mixin],
  37. data () {
  38. return {
  39. activeName: 'first',
  40. loading: false,
  41. items: '',
  42. downlist: ''
  43. }
  44. },
  45. created () {
  46. this.fetchData()
  47. },
  48. watch: {
  49. 'activeName': function (val) {
  50. if (val === 'second') {
  51. if (!this.checkOnline()) {
  52. this.$message.error('当前网络不可用,图片信息将无法加载')
  53. }
  54. }
  55. }
  56. },
  57. methods: {
  58. fetchData () {
  59. this.loading = true
  60. let softwarejson = path.join('data/sc_software.json')
  61. let softwarelist = fs.readJsonSync(softwarejson).sc_product
  62. let pid = this.$route.params.pid
  63. let loadings = true
  64. let items = softwarelist.find(function (item) {
  65. if (item.product_id === pid) {
  66. loadings = false
  67. }
  68. return item.product_id === pid
  69. })
  70. this.items = items
  71. let downlist = fs.readJsonSync(softwarejson).sc_down
  72. let newdownlist = downlist.filter(function (item) {
  73. return item.product_id === pid
  74. })
  75. this.downlist = newdownlist
  76. this.loading = loadings
  77. },
  78. downloadSoftware (downID, version) {
  79. // 先判断是否已在下载列表中,再加入列表中
  80. let downloaditem = this.$db.read().get('sc_download').find({ down_id: downID, version: version, delete: false }).value()
  81. if (!downloaditem) {
  82. this.$emit('softwareDownload', downID)
  83. } else {
  84. let info = this.downlist.find(function (item) {
  85. return item.down_id === downID
  86. })
  87. this.$message({
  88. showClose: true,
  89. message: info.fulltitle + '已存在下载列中',
  90. iconClass: '',
  91. type: 'warning'
  92. })
  93. }
  94. },
  95. checkOnline () {
  96. if (!navigator.onLine) {
  97. return false
  98. } else {
  99. return true
  100. }
  101. }
  102. }
  103. }
  104. /**
  105. * 原生方法打开v-html引入a标签的点击事件
  106. * @type {Electron}
  107. */
  108. const electron = require('electron')
  109. window.openURL = function (url) {
  110. electron.shell.openExternal(url)
  111. }
  112. </script>