addAppVersionManage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div class="versionPop">
  3. <zz-form class="add-device-form-style" :cols="formCols" :data="formData" :rules="formRules" labelWidth="120" ref="form">
  4. <!-- 产品类型 -->
  5. <el-select slot="productType" v-model="formData.productType" placeholder="请选择产品类型">
  6. <el-option v-for="(item, index) in productTypes" :key="index" :label="item.label" :value="item.id">{{
  7. item.label
  8. }}</el-option>
  9. </el-select>
  10. <!-- 手机系统 -->
  11. <el-select slot="mobileOS" v-model="formData.mobileOS" placeholder="请选择手机系统">
  12. <el-option v-for="(item, index) in phoneSystems" :key="index" :value="item.label">{{ item.label }}</el-option>
  13. </el-select>
  14. <template slot="updateContent">
  15. <el-input type="textarea" v-model="formData.remark" rows="5" resize="none"></el-input>
  16. </template>
  17. <template slot="isNewestVer">
  18. <el-radio v-model="formData.isNewestVer" :label="1">是</el-radio>
  19. <el-radio v-model="formData.isNewestVer" :label="0">否</el-radio>
  20. </template>
  21. <template slot="isForcedUpgrade">
  22. <el-radio v-model="formData.isForcedUpgrade" :label="1">是</el-radio>
  23. <el-radio v-model="formData.isForcedUpgrade" :label="0">否</el-radio>
  24. </template>
  25. <p slot="forcedUpgradeVersionNotice" class="scene-tip-style">
  26. <span>注:用户版本号<强制升级版本号,需要强制升级最新版本</span>
  27. </p>
  28. <div slot="uploadApk" class="uploadApk">
  29. <el-input class="uploadinput" slot="tip" v-model="isUpload" :placeholder="isUpload ? '' : isUploadText"></el-input>
  30. <el-upload
  31. name="avatarfile"
  32. action="/sc-community/systemConfig/addAppPackage"
  33. :headers="token"
  34. :show-file-list="true"
  35. :limit="1"
  36. accept=".apk"
  37. :data="uploads"
  38. :on-success="(response, file, fileList) => uploadsuccess(response, file, fileList)"
  39. :before-upload="beforefileUpload"
  40. :on-remove="removeFile"
  41. >
  42. <el-button size="small" type="primary">点击上传</el-button>
  43. </el-upload>
  44. </div>
  45. </zz-form>
  46. </div>
  47. </template>
  48. <script>
  49. export default {
  50. props: ['params'],
  51. data() {
  52. return {
  53. token: {
  54. [localStorage.getItem('SC_token') && 'Authorization']: 'Bearer ' + localStorage.getItem('SC_token')
  55. },
  56. uploads: {
  57. filePath: ''
  58. },
  59. phoneSystems: [
  60. {
  61. value: 1,
  62. label: '安卓'
  63. },
  64. {
  65. value: 2,
  66. label: '苹果'
  67. }
  68. ],
  69. isUpload: '',
  70. isUploadText: '请上传安装包',
  71. productTypes: [],
  72. formData: {
  73. id: '',
  74. productType: '',
  75. mobileOS: '',
  76. isNewestVer: 1,
  77. isForcedUpgrade: 1,
  78. curAppVer: '',
  79. remark: '',
  80. forcedUpgradeVer: '',
  81. download: '',
  82. verUrl: ''
  83. },
  84. formCols: [
  85. [
  86. {
  87. label: '产品类型',
  88. prop: 'productType',
  89. slot: 'productType'
  90. },
  91. {
  92. label: '手机系统',
  93. prop: 'mobileOS',
  94. slot: 'mobileOS'
  95. },
  96. {
  97. label: '当前版本',
  98. prop: 'curAppVer',
  99. input: true
  100. },
  101. {
  102. label: '更新内容',
  103. prop: 'remark',
  104. slot: 'updateContent'
  105. },
  106. {
  107. label: '是否最新版本',
  108. prop: 'isNewestVer',
  109. slot: 'isNewestVer'
  110. },
  111. {
  112. label: '是否强制升级',
  113. prop: 'isForcedUpgrade',
  114. slot: 'isForcedUpgrade'
  115. },
  116. {
  117. label: '强制升级版本',
  118. prop: 'forcedUpgradeVer',
  119. input: true
  120. },
  121. {
  122. prop: 'forcedUpgradeVersionNotice',
  123. slot: 'forcedUpgradeVersionNotice'
  124. },
  125. {
  126. label: '上传安装包',
  127. prop: 'uploadApk',
  128. slot: 'uploadApk'
  129. },
  130. {
  131. label: 'IOS下载地址',
  132. prop: 'download',
  133. input: true
  134. }
  135. ]
  136. ],
  137. formRules: {
  138. productType: [this.$valid.selectRequired('产品类型')],
  139. mobileOS: [this.$valid.selectRequired('手机系统')],
  140. curAppVer: [this.$valid.inputRequired('当前版本'), this.$valid.versionRegular()],
  141. isNewestVer: [this.$valid.selectRequired('是否最新版本')],
  142. isForcedUpgrade: [this.$valid.selectRequired('是否强制升级')],
  143. forcedUpgradeVer: [this.$valid.versionRegular()]
  144. // uploadApk:[this.$valid.inputPageRequired('上传安装包')]
  145. }
  146. };
  147. },
  148. watch: {
  149. isUpload(val) {
  150. this.isUpload = val;
  151. }
  152. },
  153. methods: {
  154. removeFile(file) {
  155. this.isUpload = '';
  156. this.isUploadText = '请上传安装包';
  157. },
  158. beforefileUpload(file) {
  159. const isApk = file.type === 'application/vnd.android.package-archive';
  160. const isApkSize = file.size > 0;
  161. let textfill = '';
  162. if (!isApk) {
  163. this.$message.error('上传文件只能是apk格式!');
  164. }
  165. if (!isApkSize) {
  166. this.$message.error('上传文件大小不能为空!');
  167. }
  168. if (this.formData.productType === '' || this.formData.curAppVer === '') {
  169. textfill = false;
  170. this.$message.error('请先填写完其他信息!');
  171. } else {
  172. textfill = true;
  173. this.isUploadText = '正在上传';
  174. this.uploads.filePath = `/${this.formData.productType}/${this.formData.curAppVer}/`;
  175. }
  176. return isApk && isApkSize && textfill;
  177. },
  178. uploadsuccess(res, file, fileList) {
  179. console.log(res);
  180. if (res.status === 0) {
  181. let str = res.data;
  182. let index = str.lastIndexOf('/');
  183. str = str.substring(index + 1, str.length);
  184. this.isUpload = str;
  185. this.formData.verUrl = res.data;
  186. } else {
  187. this.$message.error(res.msg);
  188. }
  189. },
  190. getProductType() {
  191. this.$http.post('/sc-user-center/dict/selectList', { parentDictCode: 'SYSTEM_PRODUCT_TYPE' }).then(({ status, data, msg }) => {
  192. if (0 === status) {
  193. console.log(data);
  194. let datas = [];
  195. datas = data.map((item, index) => ({
  196. id: item.dictCode,
  197. label: item.dictValue
  198. }));
  199. this.productTypes = datas;
  200. }
  201. });
  202. },
  203. submit() {
  204. new Promise((resolve) => {
  205. this.$refs.form.validate(resolve);
  206. }).then(() => {
  207. var loading = this.$loading();
  208. var posturl = '';
  209. if (this.params.todo === 'edit') {
  210. posturl = '/sc-user-center/verManage/updateVerManage';
  211. } else {
  212. posturl = '/sc-user-center/verManage/addVerManage';
  213. }
  214. this.$http
  215. .post(posturl, this.formData)
  216. .then(({ status, data, msg }) => {
  217. loading.close();
  218. if (0 == status) {
  219. console.log(this.formData);
  220. this.$message.success(msg);
  221. this.params.callback && this.params.callback();
  222. this.$emit('close');
  223. } else {
  224. this.$message.error(msg);
  225. }
  226. })
  227. .catch((err) => {
  228. loading.close();
  229. });
  230. });
  231. }
  232. },
  233. created() {
  234. this.getProductType();
  235. if ('edit' === this.params.todo) {
  236. this.__setValue('formData');
  237. if (this.params.data.verUrl) {
  238. let str = this.params.data.verUrl;
  239. let index = str.lastIndexOf('/');
  240. str = str.substring(index + 1, str.length);
  241. this.isUpload = str;
  242. }
  243. }
  244. // this.uploads.filePath = this.formData.productType+"/"+this.formData.curAppVer+"/"
  245. // this.formData = this.params.data.productTypeName
  246. // this.formData.id = this.params.data.id?this.params.data.id:this.formData.id;
  247. // this.formData.productType = this.params.data.productTypeName?this.params.data.productTypeName:this.formData.productType;
  248. // this.formData.mobileOS = this.params.data.mobileOS?this.params.data.mobileOS:this.formData.mobileOS;
  249. // this.formData.curAppVer = this.params.data.curAppVer?this.params.data.curAppVer:this.formData.curAppVer;
  250. // this.formData.remark = this.params.data.remark?this.params.data.remark:this.formData.remark;
  251. // this.formData.isNewestVer = this.params.data.isNewestVer?this.params.data.isNewestVer:this.formData.isNewestVer;
  252. // this.formData.isForcedUpgrade = this.params.data.isForcedUpgrade?this.params.data.isForcedUpgrade:this.formData.isForcedUpgrade;
  253. // this.formData.forcedUpgradeVer = this.params.data.forcedUpgradeVer?this.params.data.forcedUpgradeVer:this.formData.forcedUpgradeVer;
  254. }
  255. };
  256. </script>
  257. <style lang="scss">
  258. @import '@assets/css/public-style.scss';
  259. .versionPop {
  260. .uploadinput {
  261. width: 320px;
  262. // height: 30px;
  263. // border:1px solid #d8d8d8;
  264. // text-indent: 15px;
  265. // color:#d8d8d8;
  266. // border-radius: 5px;
  267. }
  268. }
  269. .el-upload--text {
  270. width: 80px;
  271. border: none;
  272. background: transparent;
  273. position: absolute;
  274. top: 0;
  275. left: 323px;
  276. .el-button--primary {
  277. height: 25px;
  278. line-height: 5px;
  279. }
  280. }
  281. </style>