index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. />
  12. <confirm-dialog
  13. ref="addDialog"
  14. title="新增升级"
  15. @confirm="onDeploy"
  16. >
  17. <div class="c-grid-form u-align-self--center">
  18. <span class="c-grid-form__label required">升级名称</span>
  19. <el-input
  20. v-model.trim="version.name"
  21. placeholder="最多50个字符"
  22. maxlength="50"
  23. clearable
  24. />
  25. <span class="c-grid-form__label required">目标版本</span>
  26. <input
  27. class="el-input__inner u-pointer u-ellipsis"
  28. :value="apk"
  29. placeholder="请选择目标版本"
  30. readonly
  31. @click="onChooseApk"
  32. >
  33. <span class="c-grid-form__label required">目标设备</span>
  34. <input
  35. class="el-input__inner u-pointer u-ellipsis"
  36. :value="devices"
  37. placeholder="请选择目标设备"
  38. readonly
  39. @click="chooseDevices"
  40. >
  41. <span class="c-grid-form__label">升级方式</span>
  42. <div class="l-flex--row c-grid-form__option">
  43. <el-radio>强制升级</el-radio>
  44. </div>
  45. <span class="c-grid-form__label">描述</span>
  46. <el-input
  47. v-model.trim="version.remark"
  48. type="textarea"
  49. maxlength="100"
  50. :rows="3"
  51. show-word-limit
  52. />
  53. </div>
  54. </confirm-dialog>
  55. <table-dialog
  56. ref="apkDialog"
  57. title="目标版本选择"
  58. :schema="apkSchema"
  59. append-to-body
  60. @choosen="onChoosenApk"
  61. />
  62. <el-dialog
  63. title="目标设备选择"
  64. :visible.sync="choosingDevice"
  65. custom-class="c-dialog"
  66. append-to-body
  67. >
  68. <div
  69. v-if="choosingDevice"
  70. class="l-flex__auto l-flex"
  71. >
  72. <div class="c-tree-sidebar u-overflow-y--auto">
  73. <el-tree
  74. ref="tree"
  75. :data="groups"
  76. class="c-tree-sidebar__main"
  77. node-key="path"
  78. highlight-current
  79. @node-click="onGroupTreeClick"
  80. />
  81. </div>
  82. <device-tree
  83. v-if="group"
  84. class="l-flex__fill u-overflow-y--auto"
  85. :invoke="getDevices"
  86. @change="onChooseDevices"
  87. />
  88. </div>
  89. <template #footer>
  90. <button
  91. class="o-button"
  92. @click="onChoosenDevices"
  93. >
  94. 确定
  95. </button>
  96. <button
  97. class="o-button cancel"
  98. @click="choosingDevice = false"
  99. >
  100. 取消
  101. </button>
  102. </template>
  103. </el-dialog>
  104. </wrapper>
  105. </template>
  106. <script>
  107. import {
  108. getApks,
  109. getVersions,
  110. deployVersion,
  111. delVersion
  112. } from '@/api/platform'
  113. import { getTopGroups } from '@/api/user'
  114. import { getDevicesByAdmin } from '@/api/device'
  115. export default {
  116. name: 'UpgradeDeploy',
  117. data () {
  118. return {
  119. version: {},
  120. apkSchema: {
  121. condition: { status: 1 },
  122. list: getApks,
  123. cols: [
  124. { prop: 'name', label: '文件名' },
  125. { prop: 'versionName', label: '版本名称' },
  126. { prop: 'versionCode', label: '版本号' },
  127. { prop: 'createTime', label: '创建时间' },
  128. { prop: 'remark', label: '备注' }
  129. ]
  130. },
  131. apk: '',
  132. choosingDevice: false,
  133. devices: '',
  134. schema: {
  135. condition: { status: void 0, name: '' },
  136. list: getVersions,
  137. buttons: [
  138. { type: 'add', on: this.onAdd }
  139. ],
  140. filters: [
  141. {
  142. key: 'status', type: 'select', placeholder: '全部状态',
  143. options: [
  144. { value: 1, label: '待升级' },
  145. { value: 2, label: '已升级' },
  146. { value: 3, label: '已废弃' }
  147. ]
  148. },
  149. { key: 'name', type: 'search', placeholder: '升级名称' }
  150. ],
  151. cols: [
  152. { prop: 'name', label: '升级名称' },
  153. { prop: 'fileName', label: '升级文件' },
  154. { prop: 'versionName', label: '目标版本' },
  155. { prop: 'deviceName', label: '目标设备' },
  156. { label: '升级方式', render () { return '强制升级' } },
  157. { prop: 'createTime', label: '创建时间' },
  158. { prop: 'remark', label: '备注' },
  159. { type: 'tag', width: 100, render ({ status }) {
  160. return {
  161. type: [null, 'warning', 'success', 'info'][status],
  162. label: [null, '待升级', '已升级', '已废弃'][status]
  163. }
  164. } },
  165. { type: 'invoke', render: [
  166. { label: '删除', on: this.onDel }
  167. ] }
  168. ]
  169. },
  170. groups: [],
  171. group: null
  172. }
  173. },
  174. methods: {
  175. onAdd () {
  176. this.version = {
  177. name: '',
  178. fileId: '',
  179. remark: ''
  180. }
  181. this.apk = ''
  182. this.$devices = []
  183. this.devices = ''
  184. this.$refs.addDialog.show()
  185. },
  186. onDeploy (done) {
  187. if (!this.version.name) {
  188. this.$message({
  189. type: 'warning',
  190. message: '请填写升级名称'
  191. })
  192. return
  193. }
  194. if (!this.version.fileId) {
  195. this.$message({
  196. type: 'warning',
  197. message: '请选择目标版本'
  198. })
  199. return
  200. }
  201. if (!this.$devices?.length) {
  202. this.$message({
  203. type: 'warning',
  204. message: '请选择目标设备'
  205. })
  206. return
  207. }
  208. deployVersion({
  209. deviceId: this.$devices.map(device => device.id),
  210. ...this.version
  211. }).then(() => {
  212. done()
  213. this.$refs.table.resetCondition({ status: 1, name: this.version.name })
  214. })
  215. },
  216. onChooseApk () {
  217. this.$refs.apkDialog.show()
  218. },
  219. onChoosenApk ({ value: { id, versionName, versionCode }, done }) {
  220. done()
  221. this.apk = `${versionName} ${versionCode}`
  222. this.version.fileId = id
  223. },
  224. chooseDevices () {
  225. this.getTopGroups().then(({ data }) => {
  226. if (data.length) {
  227. this.choosingDevice = true
  228. this.groups = data
  229. this.group = this.groups[0]
  230. this.$slectedDevices = []
  231. this.$nextTick(() => {
  232. this.$refs.tree.setCurrentKey(this.group.path)
  233. })
  234. } else {
  235. this.$message({
  236. type: 'warning',
  237. message: '请先添加租户'
  238. })
  239. }
  240. })
  241. },
  242. getTopGroups () {
  243. if (this.groups.length === 0) {
  244. return getTopGroups()
  245. }
  246. return Promise.resolve({ data: this.groups })
  247. },
  248. onGroupTreeClick (group) {
  249. if (!this.group || this.group.id !== group.id) {
  250. this.group = null
  251. this.$nextTick(() => {
  252. this.group = group
  253. })
  254. }
  255. },
  256. getDevices (params) {
  257. return getDevicesByAdmin({ tenant: this.group.path, ...params })
  258. },
  259. onChooseDevices (devices) {
  260. this.$slectedDevices = devices
  261. },
  262. onChoosenDevices () {
  263. if (this.$slectedDevices.length) {
  264. this.$devices = this.$slectedDevices
  265. this.devices = this.$slectedDevices.map(({ name }) => name).join(', ')
  266. }
  267. this.choosingDevice = false
  268. },
  269. onDel (version) {
  270. delVersion(version).then(() => {
  271. this.$refs.table.decrease(1)
  272. })
  273. }
  274. }
  275. }
  276. </script>