version_add_detail_mixin.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {
  2. validator,
  3. enumConverter
  4. } from '@/js_sdk/validator/opendb-app-versions.js';
  5. const platform_iOS = 'iOS';
  6. const platform_Android = 'Android';
  7. function getValidator(fields) {
  8. let reuslt = {}
  9. for (let key in validator) {
  10. if (fields.includes(key)) {
  11. reuslt[key] = validator[key]
  12. }
  13. }
  14. return reuslt
  15. }
  16. export const fields =
  17. 'appid,name,title,contents,platform,type,version,min_uni_version,url,stable_publish,is_silently,is_mandatory,create_date,store_list'
  18. export default {
  19. data() {
  20. return {
  21. labelWidth: '80px',
  22. enableiOSWgt: true, // 是否开启iOS的wgt更新
  23. silentlyContent: '静默更新:App升级时会在后台下载wgt包并自行安装。新功能在下次启动App时生效',
  24. mandatoryContent: '强制更新:App升级弹出框不可取消',
  25. stablePublishContent: '同时只可有一个线上发行版,线上发行不可更设为下线。\n未上线可以设为上线发行并自动替换当前线上发行版',
  26. stablePublishContent2: '使用本包替换当前线上发行版',
  27. uploadFileContent: '可下载安装包地址。上传文件到云存储自动填写,也可以手动填写',
  28. minUniVersionContent: '上次使用新Api或打包新模块的App版本',
  29. priorityContent: '检查更新时,按照优先级从大到小依次尝试跳转商店。如果都跳转失败,则会打开浏览器使用下载链接下载apk安装包',
  30. latestStableData: [], // 库中最新已上线版
  31. appFileList: null, // 上传包
  32. type_valuetotext: enumConverter.type_valuetotext,
  33. preUrl: '',
  34. formData: {
  35. "appid": "",
  36. "name": "",
  37. "title": "",
  38. "contents": "",
  39. "platform": [],
  40. "store_list": [],
  41. "type": "",
  42. "version": "",
  43. "min_uni_version": "",
  44. "url": "",
  45. "stable_publish": false,
  46. "create_date": null
  47. },
  48. formOptions: {
  49. "platform_localdata": [{
  50. "value": "Android",
  51. "text": "安卓"
  52. },
  53. {
  54. "value": "iOS",
  55. "text": "苹果"
  56. }
  57. ],
  58. "type_localdata": [{
  59. "value": "native_app",
  60. "text": "原生App安装包"
  61. },
  62. {
  63. "value": "wgt",
  64. "text": "App资源包"
  65. }
  66. ]
  67. },
  68. rules: {
  69. ...getValidator(["appid", "contents", "platform", "type", "version", "min_uni_version", "url",
  70. "stable_publish",
  71. "title", "name", "is_silently", "is_mandatory", "store_list"
  72. ])
  73. }
  74. }
  75. },
  76. onReady() {
  77. this.$refs.form.setRules(this.rules)
  78. },
  79. computed: {
  80. isWGT() {
  81. return this.formData.type === 'wgt'
  82. },
  83. isiOS() {
  84. return !this.isWGT ? this.formData.platform.includes(platform_iOS) : false;
  85. },
  86. hasPackage() {
  87. return this.appFileList && !!Object.keys(this.appFileList).length
  88. },
  89. fileExtname() {
  90. return this.isWGT ? ['wgt'] : ['apk']
  91. },
  92. platformLocaldata() {
  93. return !this.isWGT ? this.formOptions.platform_localdata : this.enableiOSWgt ? this.formOptions
  94. .platform_localdata : [this.formOptions.platform_localdata[0]]
  95. },
  96. uni_platform() {
  97. return (this.isiOS ? platform_iOS : platform_Android).toLocaleLowerCase()
  98. }
  99. },
  100. methods: {
  101. packageUploadSuccess(res) {
  102. uni.showToast({
  103. icon: 'success',
  104. title: '上传成功',
  105. duration: 800
  106. })
  107. this.preUrl = this.formData.url
  108. this.formData.url = res.tempFilePaths[0]
  109. },
  110. async packageDelete(res) {
  111. if (!this.hasPackage) return;
  112. let [deleteRes] = await this.$request('deleteFile', {
  113. fileList: [res.tempFilePath]
  114. }, {
  115. functionName: 'uni-app-manager'
  116. })
  117. if (deleteRes.success) {
  118. uni.showToast({
  119. icon: 'success',
  120. title: '删除成功',
  121. duration: 800
  122. })
  123. this.formData.url = this.preUrl
  124. this.$refs.form.clearValidate('url')
  125. }
  126. },
  127. selectFile() {
  128. if (this.hasPackage) {
  129. uni.showToast({
  130. icon: 'none',
  131. title: '只可上传一个文件,请删除已上传后重试',
  132. duration: 1000
  133. });
  134. }
  135. },
  136. createCenterRecord(value) {
  137. return {
  138. ...value,
  139. uni_platform: this.uni_platform,
  140. create_env: 'upgrade-center'
  141. }
  142. },
  143. createCenterQuery({
  144. appid
  145. }) {
  146. return {
  147. appid,
  148. create_env: 'upgrade-center'
  149. }
  150. },
  151. createStatQuery({
  152. appid,
  153. type,
  154. version,
  155. uni_platform
  156. }) {
  157. return {
  158. appid,
  159. type,
  160. version,
  161. uni_platform: uni_platform ? uni_platform : this.uni_platform,
  162. create_env: 'uni-stat',
  163. stable_publish: false
  164. }
  165. }
  166. }
  167. }