SoftwareStartup.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="software-startup software-wrap" v-loading="loading" element-loading-text="正在获取本地数据中,请稍候...">
  3. <div class="software-left border-right border-top">
  4. <div class="local-software">
  5. <div class="software media p-3" v-for="product in productlist" :key="product.id" :class="[products.id === product.id ? 'active' : '']">
  6. <img class="mr-2" :src="product.src" width="25" height="25" :alt="product.title">
  7. <div class="media-body">
  8. <div class="mt-0 mb-1"><router-link :to="{ name: 'software-startup-detail', params: { productid: product.id } }">{{ product.title }}</router-link></div>
  9. </div>
  10. </div>
  11. </div>
  12. <div class="software-left-bottom border-top">
  13. <div class="d-flex bd-highlight">
  14. <div class="p-2 flex-fill bd-highlight">
  15. <el-button style="width:100%;" type="primary" class="btn btn-primary btn-blue btn-sm" @click="openlist('software-list')">下载软件</el-button>
  16. </div>
  17. <div class="p-2 flex-fill bd-highlight">
  18. <el-dropdown placement="top" trigger="click" style="width:100%;" @command="clickbtn">
  19. <el-button type="primary" style="width:100%;" class="btn btn-primary btn-blue btn-sm">
  20. 添加软件<i class="el-icon-arrow-up el-icon--right"></i>
  21. </el-button>
  22. <el-dropdown-menu class="command-menu" slot="dropdown">
  23. <el-dropdown-item class="command-item" command="auto">自动获取</el-dropdown-item>
  24. <el-dropdown-item class="command-item" command="manual">手动添加</el-dropdown-item>
  25. </el-dropdown-menu>
  26. </el-dropdown>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <software-startup-detail ref="startupDetail"></software-startup-detail>
  32. </div>
  33. </template>
  34. <script>
  35. import mixin from '../mixin'
  36. import SoftwareStartupDetail from './SoftwareStartupDetail'
  37. export default {
  38. mixins: [mixin],
  39. components: { SoftwareStartupDetail },
  40. data () {
  41. return {
  42. activeName: 'first',
  43. productlist: '',
  44. products: '',
  45. loading: false
  46. }
  47. },
  48. created () {
  49. this.fetchData()
  50. let self = this
  51. this.$electron.ipcRenderer.on('successUpdate', (event, msg) => {
  52. try {
  53. self.loading = false
  54. let num = msg.num
  55. let delnum = msg.delnum
  56. this.$electron.ipcRenderer.send('testUsb')
  57. if (num !== 0 && delnum !== 0) {
  58. self.$message({
  59. message: `新增了 ${num} 个纵横软件`,
  60. type: 'success'
  61. })
  62. setTimeout(function () {
  63. self.$message({
  64. message: `移除了 ${delnum} 个纵横软件`,
  65. type: 'error'
  66. })
  67. }, 2000)
  68. } else {
  69. if (delnum !== 0) {
  70. self.$message({
  71. message: `移除了 ${delnum} 个纵横软件`,
  72. type: 'error'
  73. })
  74. }
  75. if (num !== 0) {
  76. self.$message({
  77. message: `新增了 ${num} 个纵横软件`,
  78. type: 'success'
  79. })
  80. }
  81. if (num === 0 && delnum === 0) {
  82. self.$message.info('更新没有获取到新的纵横软件')
  83. }
  84. }
  85. let id = msg.id
  86. // 如果不跳转出本产品,则让downlist 每次都执行更新一遍
  87. if (self.$route.params.productid === id) {
  88. self.fetchData()
  89. if (self.$refs.startupDetail !== undefined) {
  90. self.$refs.startupDetail.fetchData()
  91. }
  92. } else {
  93. self.$router.push({
  94. name: 'software-startup-detail',
  95. params: {productid: id}
  96. })
  97. }
  98. } catch (err) {
  99. console.log(err)
  100. }
  101. })
  102. this.$electron.ipcRenderer.on('failedUpdate', (event, msg) => {
  103. try {
  104. self.loading = false
  105. self.$message.info('你的电脑还没安装过纵横软件')
  106. console.log(msg.error)
  107. let id = msg.id
  108. this.$electron.ipcRenderer.send('testUsb')
  109. if (self.$route.params.productid === id && msg.error !== 200) {
  110. self.fetchData()
  111. if (self.$refs.startupDetail !== undefined) {
  112. self.$refs.startupDetail.fetchData()
  113. }
  114. } else {
  115. self.$router.push({
  116. name: 'software-startup-detail',
  117. params: { productid: id }
  118. })
  119. }
  120. } catch (err) {
  121. console.log(err)
  122. }
  123. })
  124. this.$electron.ipcRenderer.on('failedDirectory', (event, result) => {
  125. self.loading = false
  126. if (result.msg !== '') {
  127. self.$message({
  128. message: result.msg,
  129. type: 'error'
  130. })
  131. }
  132. })
  133. },
  134. watch: {
  135. // 如果路由有变化,会再次执行该方法
  136. '$route': 'fetchData'
  137. },
  138. methods: {
  139. fetchData () {
  140. let pid = this.$route.params.productid === undefined ? this.$db.read().get('sc_productData').last().value().id : this.$route.params.productid
  141. this.products = this.$db.read().get('sc_productData').getById(pid).value()
  142. this.productlist = this.$db.read().get('sc_productData').filter({ isshow: true }).orderBy('addtime', 'desc').value()
  143. },
  144. openlist (index) {
  145. this.$router.push({
  146. name: index
  147. })
  148. },
  149. clickbtn (command) {
  150. this.loading = true
  151. if (command === 'auto') {
  152. this.$electron.ipcRenderer.send('updateInstall')
  153. } else {
  154. this.$electron.ipcRenderer.send('file-select')
  155. }
  156. }
  157. }
  158. }
  159. </script>
  160. <style>
  161. .software-left {
  162. position: absolute;
  163. width: 250px;
  164. top: 59px;
  165. bottom: 0;
  166. left: 0;
  167. }
  168. .border-right {
  169. border-right: 1px solid #dee2e6!important;
  170. }
  171. .border-top {
  172. border-top: 1px solid #dee2e6!important;
  173. }
  174. .local-software {
  175. position: absolute;
  176. width: 100%;
  177. top: 0;
  178. left: 0;
  179. bottom: 50px;
  180. /* background: #f9f9f9; */
  181. background-color: rgba(254,250,249,0.3);
  182. overflow-y: auto;
  183. }
  184. .software-left-bottom {
  185. background-color: rgba(251,231,216,0.5);
  186. z-index: 999;
  187. position: absolute;
  188. width: 100%;
  189. bottom: 0;
  190. left: 0;
  191. }
  192. .local-install {
  193. position: absolute;
  194. top: 80px;
  195. right: 0;
  196. bottom: 0;
  197. width: 648px;
  198. overflow-y: auto;
  199. }
  200. .software.active {
  201. background: #fdf5f2;
  202. border-left: 3px solid #ff6501;
  203. }
  204. .software.active a {
  205. color: #333;
  206. }
  207. .software a {
  208. text-decoration: none;
  209. }
  210. .d-flex {
  211. display: -ms-flexbox!important;
  212. display: flex!important;
  213. }
  214. .flex-fill {
  215. -ms-flex: 1 1 auto!important;
  216. flex: 1 1 auto!important;
  217. }
  218. .software-content {
  219. height: 337px;
  220. overflow-y: auto;
  221. padding-right: 15px;
  222. }
  223. .details {
  224. padding: 15px 0;
  225. border-bottom: 1px dotted #ccc;
  226. }
  227. .details:hover{
  228. border-bottom:1px solid #ff6501;
  229. }
  230. .w-25 {
  231. width: 25%!important;
  232. }
  233. .w-50 {
  234. width: 50%!important;
  235. }
  236. .d-inline-block {
  237. display: inline-block!important;
  238. }
  239. .command-menu {
  240. padding: .5rem 0 !important;
  241. color: #212529 !important;
  242. border-radius: .25rem !important;
  243. margin: .125rem 0 0 !important;
  244. font-size: 1rem !important;
  245. }
  246. .command-item {
  247. font-size: 1rem !important;
  248. }
  249. .el-popper[x-placement^=top] {
  250. margin-bottom: 5px!important;
  251. }
  252. </style>