detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="uni-container">
  3. <view class="uni-header">
  4. <view class="uni-group">
  5. <view class="uni-title">包类型</view>
  6. <view class="uni-sub-title" style="display: flex;justify-content: center;align-items: center;">
  7. {{type_valuetotext[formData.type]}}
  8. </view>
  9. </view>
  10. <view v-if="!isStable" class="uni-group">
  11. <button class="uni-button" type="warn" size="mini" @click="deletePackage">删除</button>
  12. </view>
  13. </view>
  14. <uni-forms ref="form" :value="formData" validateTrigger="bind" :labelWidth="labelWidth">
  15. <uni-forms-item name="appid" label="AppID" required>
  16. <uni-easyinput :disabled="true" v-model="formData.appid" trim="both" />
  17. </uni-forms-item>
  18. <uni-forms-item name="name" label="应用名称">
  19. <uni-easyinput :disabled="true" v-model="formData.name" trim="both" />
  20. </uni-forms-item>
  21. <uni-forms-item name="title" label="更新标题">
  22. <uni-easyinput :disabled="detailsState" placeholder="更新标题" v-model="formData.title" />
  23. </uni-forms-item>
  24. <uni-forms-item name="contents" label="更新内容" required>
  25. <textarea auto-height style="box-sizing: content-box;" :disabled="detailsState"
  26. @input="binddata('contents', $event.detail.value)" class="uni-textarea-border"
  27. :value="formData.contents" @update:value="val => formData.contents = val"></textarea>
  28. </uni-forms-item>
  29. <uni-forms-item name="platform" label="平台" required>
  30. <uni-data-checkbox :disabled="true" :multiple="true" v-model="formData.platform"
  31. :localdata="platformLocaldata" />
  32. </uni-forms-item>
  33. <uni-forms-item name="version" label="版本号" required>
  34. <uni-easyinput :disabled="true" v-model="formData.version" placeholder="当前包版本号,必须大于当前已上线版本号" />
  35. </uni-forms-item>
  36. <uni-forms-item v-if="isWGT" key="min_uni_version" name="min_uni_version" label="原生App最低版本"
  37. :required="isWGT">
  38. <uni-easyinput :disabled="detailsState" placeholder="原生App最低版本" v-model="formData.min_uni_version" />
  39. <show-info :content="minUniVersionContent"></show-info>
  40. </uni-forms-item>
  41. <uni-forms-item v-if="!isiOS && !detailsState" label="上传apk包">
  42. <uni-file-picker v-model="appFileList" :file-extname="fileExtname" :disabled="hasPackage"
  43. returnType="object" file-mediatype="all" limit="1" @success="packageUploadSuccess"
  44. @delete="packageDelete">
  45. <button type="primary" size="mini" @click="selectFile">选择文件</button>
  46. </uni-file-picker>
  47. <text v-if="hasPackage"
  48. style="padding-left: 20px;color: #a8a8a8;">{{Number(appFileList.size / 1024 / 1024).toFixed(2)}}M</text>
  49. </uni-forms-item>
  50. <uni-forms-item key="url" name="url" :label="isiOS ? 'AppStore' : '下载链接'" required>
  51. <uni-easyinput :disabled="detailsState" placeholder="下载链接" v-model="formData.url" :maxlength="-1" />
  52. <!-- <show-info :top="-80" :content="uploadFileContent"></show-info> -->
  53. </uni-forms-item>
  54. <uni-forms-item v-if="!isiOS && !isWGT && formData.store_list.length" label="Android应用市场" key="store_list"
  55. name="store_list" labelWidth="120">
  56. <view style="flex: 1;">
  57. <view v-for="(item,index) in formData.store_list" :key="item.id">
  58. <uni-card style="margin: 0px 0px 20px 0px;">
  59. <view style="display: flex;">
  60. <checkbox-group style="user-select: none;"
  61. @change="({detail:{value}}) => {item.enable = !!value.length}">
  62. <label class="title_padding">
  63. <checkbox :disabled="detailsState" value="scheme" :checked="item.enable" />
  64. <text>是否启用</text>
  65. </label>
  66. </checkbox-group>
  67. </view>
  68. <uni-forms-item label="商店名称">
  69. <uni-easyinput disabled v-model="item.name" trim="both"></uni-easyinput>
  70. </uni-forms-item>
  71. <uni-forms-item label="Scheme">
  72. <uni-easyinput disabled v-model="item.scheme" trim="both"></uni-easyinput>
  73. </uni-forms-item>
  74. <uni-forms-item label="优先级">
  75. <uni-easyinput :disabled="detailsState" v-model="item.priority" type="number">
  76. </uni-easyinput>
  77. <show-info :top="-100" :left="-180" :content="priorityContent"></show-info>
  78. </uni-forms-item>
  79. </uni-card>
  80. </view>
  81. </view>
  82. </uni-forms-item>
  83. <uni-forms-item v-if="isWGT" key="is_silently" name="is_silently" label="静默更新">
  84. <switch :disabled="detailsState"
  85. @change="binddata('is_silently', $event.detail.value),formData.is_silently=$event.detail.value"
  86. :checked="formData.is_silently" />
  87. <show-info :top="-80" :content="silentlyContent"></show-info>
  88. </uni-forms-item>
  89. <uni-forms-item v-if="!isiOS" key="is_mandatory" name="is_mandatory" label="强制更新">
  90. <switch :disabled="detailsState"
  91. @change="binddata('is_mandatory', $event.detail.value),formData.is_mandatory=$event.detail.value"
  92. :checked="formData.is_mandatory" />
  93. <show-info width="230" :top="-30" :content="mandatoryContent"></show-info>
  94. </uni-forms-item>
  95. <uni-forms-item name="stable_publish" label="上线发行">
  96. <switch :disabled="detailsState || isStable"
  97. @change="binddata('stable_publish', $event.detail.value),formData.stable_publish=$event.detail.value"
  98. :checked="formData.stable_publish" />
  99. <show-info v-if="isStable" :top="-50" width="350" :content="stablePublishContent"></show-info>
  100. <show-info v-else :top="-40" :content="stablePublishContent2"></show-info>
  101. </uni-forms-item>
  102. <uni-forms-item name="create_date" label="上传时间">
  103. <uni-dateformat format="yyyy-MM-dd hh:mm:ss" :date="formData.create_date" :threshold="[0, 0]" />
  104. </uni-forms-item>
  105. <uni-forms-item v-show="false" name="type" label="安装包类型">
  106. <uni-data-checkbox v-model="formData.type" :localdata="formOptions.type_localdata" />
  107. </uni-forms-item>
  108. <view class="uni-button-group">
  109. <button type="primary" class="uni-button" style="width: 100px;" @click="detailsState = false"
  110. v-if="detailsState">修改</button>
  111. <button type="primary" class="uni-button" style="width: 100px;" @click="submit"
  112. v-if="!detailsState">提交</button>
  113. <button type="warn" class="uni-button" style="width: 100px;" @click="cancelEdit"
  114. v-if="!detailsState">取消</button>
  115. <navigator open-type="navigateBack" style="margin-left: 15px;">
  116. <button class="uni-button" style="width: 100px;">返回</button>
  117. </navigator>
  118. </view>
  119. </uni-forms>
  120. </view>
  121. </template>
  122. <script>
  123. import {
  124. validator,
  125. enumConverter
  126. } from '@/js_sdk/validator/opendb-app-versions.js';
  127. import addAndDetail, {
  128. fields
  129. } from '../mixin/version_add_detail_mixin.js'
  130. import {
  131. deepClone,
  132. appVersionListDbName
  133. } from '../utils.js'
  134. const db = uniCloud.database();
  135. const dbCmd = db.command;
  136. const dbCollectionName = appVersionListDbName;
  137. const platform_iOS = 'iOS';
  138. const platform_Android = 'Android';
  139. function getValidator(fields) {
  140. let reuslt = {}
  141. for (let key in validator) {
  142. if (fields.includes(key)) {
  143. reuslt[key] = validator[key]
  144. }
  145. }
  146. return reuslt
  147. }
  148. export default {
  149. mixins: [addAndDetail],
  150. data() {
  151. return {
  152. showStableInfo: false,
  153. isStable: true, // 是否是线上发行版
  154. originalData: {}, // 原始数据,用于恢复状态
  155. detailsState: true // 查看状态
  156. }
  157. },
  158. async onLoad(e) {
  159. const id = e.id
  160. this.formDataId = id
  161. await this.getDetail(id)
  162. this.isStable = this.formData.stable_publish;
  163. this.latestStableData = await this.getLatestVersion();
  164. if (this.isWGT) {
  165. this.rules.min_uni_version.rules.push({
  166. "required": true
  167. })
  168. }
  169. },
  170. methods: {
  171. /**
  172. * 触发表单提交
  173. */
  174. submit() {
  175. uni.showLoading({
  176. mask: true
  177. })
  178. this.$refs.form.validate(['store_list']).then((res) => {
  179. if (res.store_list) {
  180. res.store_list.forEach(item => {
  181. item.priority = parseFloat(item.priority)
  182. })
  183. }
  184. this.submitForm(res)
  185. }).catch((errors) => {
  186. uni.hideLoading()
  187. })
  188. },
  189. async submitForm(value) {
  190. const collectionDB = db.collection(dbCollectionName)
  191. // 使用 clientDB 提交数据
  192. collectionDB.doc(this.formDataId).update(value).then(async (res) => {
  193. // 如果不是线上发行版,则在设置为上线发行时,需将之前的已上线版设为下线
  194. if (!this.isStable && value.stable_publish === true && this.latestStableData) {
  195. await collectionDB.doc(this.latestStableData._id).update({
  196. stable_publish: false
  197. })
  198. }
  199. uni.showToast({
  200. title: '修改成功'
  201. })
  202. this.getOpenerEventChannel().emit('refreshData')
  203. setTimeout(() => uni.navigateBack(), 500)
  204. }).catch((err) => {
  205. uni.showModal({
  206. content: err.message || '请求服务失败',
  207. showCancel: false
  208. })
  209. }).finally(() => {
  210. uni.hideLoading()
  211. })
  212. },
  213. /**
  214. * 获取表单数据
  215. * @param {Object} id
  216. */
  217. getDetail(id) {
  218. uni.showLoading({
  219. mask: true
  220. })
  221. return db.collection(dbCollectionName)
  222. .doc(id)
  223. .field(fields)
  224. .get()
  225. .then((res) => {
  226. const data = res.result.data[0]
  227. if (data) {
  228. this.formData = data
  229. this.originalData = deepClone(this.formData)
  230. }
  231. }).catch((err) => {
  232. uni.showModal({
  233. content: err.message || '请求服务失败',
  234. showCancel: false
  235. })
  236. }).finally(() => {
  237. uni.hideLoading()
  238. })
  239. },
  240. deletePackage() {
  241. uni.showModal({
  242. title: '提示',
  243. content: '是否删除该版本',
  244. success: res => {
  245. if (res.confirm) {
  246. uni.showLoading({
  247. mask: true
  248. })
  249. db.collection(dbCollectionName).doc(this.formDataId).remove()
  250. .then(() => {
  251. uni.showToast({
  252. title: '删除成功'
  253. })
  254. this.getOpenerEventChannel().emit('refreshData')
  255. setTimeout(() => uni.navigateBack(), 500)
  256. }).catch((err) => {
  257. uni.showModal({
  258. content: err.message || '请求服务失败',
  259. showCancel: false
  260. })
  261. }).finally(() => {
  262. uni.hideLoading()
  263. })
  264. }
  265. }
  266. });
  267. },
  268. async getLatestVersion() {
  269. const where = {
  270. appid: this.formData.appid,
  271. type: this.formData.type,
  272. stable_publish: true
  273. };
  274. if (!this.isWGT) {
  275. where.platform = this.formData.platform[0]
  276. }
  277. const latestStableData = await db.collection(dbCollectionName).where(where).get()
  278. return latestStableData.result.data.find(item => item.platform.toString() === this.formData.platform
  279. .toString());
  280. },
  281. cancelEdit() {
  282. let content = '';
  283. !this.isiOS && this.hasPackage ? content += '\n将会删除已上传的包' : '';
  284. uni.showModal({
  285. title: '取消修改',
  286. content,
  287. success: res => {
  288. if (res.confirm) {
  289. this.formData = deepClone(this.originalData)
  290. this.detailsState = true
  291. if (this.hasPackage) {
  292. let fileList = [];
  293. fileList.push(this.appFileList.url)
  294. this.$request('deleteFile', {
  295. fileList
  296. }, {
  297. functionName: 'upgrade-center'
  298. })
  299. }
  300. }
  301. }
  302. });
  303. }
  304. }
  305. }
  306. </script>
  307. <style lang="scss">
  308. .show-stable-info {
  309. position: absolute;
  310. left: 165px;
  311. padding: 5px 10px;
  312. background-color: #f4f4f5;
  313. color: #909399;
  314. border-radius: 4px;
  315. border: 1px solid #e9e9eb;
  316. }
  317. ::v-deep .uni-forms-item__content {
  318. display: flex;
  319. align-items: center;
  320. }
  321. .uni-button-group {
  322. & button {
  323. margin-left: 15px;
  324. }
  325. & button:first-child {
  326. margin-left: 0px;
  327. }
  328. }
  329. </style>