add.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view class="uni-container">
  3. <uni-notice-bar style="margin: 0;" showIcon text="本页面信息,在应用发布、app升级模块中,都会关联使用,请认真填写" />
  4. <uni-forms ref="form" v-model="formData" validateTrigger="bind" style="max-width: 792px;"
  5. :labelWidth="labelWidth" :rules="rules">
  6. <uni-card title="基础信息">
  7. <uni-forms-item class="forn-item__flex" name="appid" label="AppID" required>
  8. <uni-easyinput :disabled="isEdit" placeholder="应用的AppID" v-model="formData.appid" trim="both">
  9. </uni-easyinput>
  10. </uni-forms-item>
  11. <uni-forms-item name="name" label="应用名称" required>
  12. <uni-easyinput :disabled="isEdit" placeholder="应用名称" v-model="formData.name" trim="both">
  13. </uni-easyinput>
  14. </uni-forms-item>
  15. <uni-forms-item name="introduction" label="应用简介">
  16. <uni-easyinput placeholder="应用简介" v-model="formData.introduction" trim="both"></uni-easyinput>
  17. </uni-forms-item>
  18. <uni-forms-item name="description" label="应用描述">
  19. <textarea :maxlength="-1" auto-height placeholder="应用描述"
  20. @input="binddata('description', $event.detail.value)" class="uni-textarea-border"
  21. v-model="formData.description"></textarea>
  22. </uni-forms-item>
  23. </uni-card>
  24. <uni-card title="图标素材">
  25. <uni-forms-item label="应用图标">
  26. <uni-file-picker v-model="middleware_img.icon_url" :image-styles="{'width' : '200rpx'}"
  27. return-type="object" file-mediatype="image" limit="1" mode="grid"
  28. @success="(res) => iconUrlSuccess(res,'icon_url')"
  29. @delete="(res) => iconUrlDelete(res,'icon_url')">
  30. </uni-file-picker>
  31. </uni-forms-item>
  32. <uni-forms-item label="应用截图">
  33. <uni-file-picker v-model="screenshotList" file-mediatype="image" mode="grid"
  34. :image-styles="{'height': '500rpx','width' : '300rpx'}" @delete="iconUrlDelete">
  35. </uni-file-picker>
  36. </uni-forms-item>
  37. </uni-card>
  38. <uni-card class="app_platform" title="App 信息">
  39. <view v-if="isEdit" class="extra-button">
  40. <button type="primary" plain size="mini" @click="autoFillApp">自动填充</button>
  41. <show-info :left="-10" :top="-35" width="230" content="从App升级中心同步应用安装包信息" />
  42. </view>
  43. <view v-for="item in appPlatformKeys" :key="item">
  44. <checkbox-group @change="({detail:{value}}) => {setPlatformChcekbox(item,!!value.length)}">
  45. <label class="title_padding" :class="{'font_bold':getPlatformChcekbox(item)}">
  46. <checkbox :value="item" :checked="middleware_checkbox[item]" />
  47. <text>{{appPlatformValues[item]}}</text>
  48. </label>
  49. </checkbox-group>
  50. <template v-if="getPlatformChcekbox(item)">
  51. <uni-forms-item label="名称">
  52. <uni-easyinput v-model="formData[item].name" trim="both"></uni-easyinput>
  53. </uni-forms-item>
  54. <uni-forms-item class="forn-item__flex" v-if="item === 'app_android'" label="上传apk包">
  55. <uni-file-picker v-model="appPackageInfo" file-extname="apk" :disabled="hasPackage"
  56. returnType="object" file-mediatype="all" limit="1"
  57. @success="(res) => iconUrlSuccess(res, `${item}.url`)"
  58. @delete="(res) => iconUrlDelete(res,`${item}.url`)" style="flex:1;">
  59. <view class="flex">
  60. <button type="primary" size="mini" @click="selectFile"
  61. style="margin: 0;">选择文件</button>
  62. <text style="padding: 10px;font-size: 12px;color: #666;">
  63. 上传apk到当前服务空间的云存储中,上传成功后,会自动使用云存储地址填充下载链接
  64. </text>
  65. </view>
  66. </uni-file-picker>
  67. <text v-if="hasPackage" style="padding-left: 20px;color: #a8a8a8;">
  68. {{appPackageInfo.size && Number(appPackageInfo.size / 1024 / 1024).toFixed(2) + 'M'}}
  69. </text>
  70. </uni-forms-item>
  71. <uni-forms-item :label="item === 'app_ios' ? 'AppStore' : '下载链接'">
  72. <uni-easyinput :maxlength="-1" v-model="formData[item].url" trim="both"></uni-easyinput>
  73. </uni-forms-item>
  74. </template>
  75. </view>
  76. <uni-popup ref="scheme" background-color="#fff">
  77. <view class="popup-content">
  78. <text style="font-size: 15px;font-weight: bold;">
  79. 常见的应用商店 scheme 地址
  80. </text>
  81. <view></view>
  82. <text>
  83. 应用宝:tmast://appdetails?r=XXX&pname=xxx;
  84. 小米:mimarket://details?id=com.xx.xx;
  85. 三星:samsungapps://ProductDetail/com.xx.xx;
  86. 华为:appmarket://details?id=com.xx.xx;
  87. oppo:oppomarket://details?packagename=com.xx.xx;
  88. vivo:vivomarket://details?id=com.xx.xx;
  89. </text>
  90. </view>
  91. </uni-popup>
  92. <uni-forms-item name="store_schemes" label="Android应用市场" labelWidth="120">
  93. <view style="height: 100%;">
  94. <view class="flex" style="justify-content: end;">
  95. <text class="pointer"
  96. style="text-decoration: underline;color: #666;font-size: 12px;padding-left: 10rpx;"
  97. @click="schemeDemo">常见应用商店schema汇总</text>
  98. <button type="primary" size="mini" @click="addStoreScheme"
  99. style="margin: 0 0 0 10px;">新增</button>
  100. </view>
  101. <view v-for="(item,index) in formData.store_list" :key="item.id">
  102. <uni-card title="" style="margin: 20px 0px 0px 0px;">
  103. <view style="display: flex;">
  104. <view style="padding-left: 10px;">
  105. <button type="warn" size="mini" @click="deleteStore(index, item)">删除</button>
  106. </view>
  107. </view>
  108. <uni-forms-item label="商店名称">
  109. <uni-easyinput v-model="item.name" trim="both"></uni-easyinput>
  110. </uni-forms-item>
  111. <uni-forms-item label="Scheme">
  112. <uni-easyinput :maxlength="-1" v-model="item.scheme" trim="both"></uni-easyinput>
  113. </uni-forms-item>
  114. </uni-card>
  115. </view>
  116. </view>
  117. </uni-forms-item>
  118. </uni-card>
  119. <uni-card class="mp_platform" title="小程序/快应用信息">
  120. <!-- <view class="extra-button">
  121. <button type="primary" plain size="mini" @click="mpAccordion">{{mpExtra}}</button>
  122. <show-info :left="40" :top="-20" content="折叠状态下,即使勾选也不会显示详情" />
  123. </view> -->
  124. <view v-for="item in mpPlatformKeys" :key="item">
  125. <checkbox-group @change="({detail:{value}}) => {setPlatformChcekbox(item,!!value.length)}">
  126. <label class="title_padding" :class="{'font_bold':getPlatformChcekbox(item)}">
  127. <checkbox :value="item" :checked="middleware_checkbox[item]" />
  128. <text>{{mpPlatform[item]}}</text>
  129. </label>
  130. </checkbox-group>
  131. <template v-if="mpAccordionStatus && getPlatformChcekbox(item)">
  132. <uni-forms-item label="名称">
  133. <uni-easyinput v-model="formData[item].name" trim="both"></uni-easyinput>
  134. </uni-forms-item>
  135. <uni-forms-item :label="mpPlatform[item].slice(-3) + '码'">
  136. <uni-file-picker v-model="middleware_img[item]" :image-styles="{'width' : '200rpx'}"
  137. return-type="object" file-mediatype="image" limit="1" mode="grid"
  138. @success="(res) => iconUrlSuccess(res, `${item}.qrcode_url`)"
  139. @delete="(res) => iconUrlDelete(res, `${item}.qrcode_url`)">
  140. </uni-file-picker>
  141. </uni-forms-item>
  142. </template>
  143. </view>
  144. </uni-card>
  145. <uni-card title="web信息">
  146. <uni-forms-item label="链接地址">
  147. <uni-easyinput :maxlength="-1" v-model="formData.h5.url" trim="both"></uni-easyinput>
  148. <span style="font-size: 13px; color: #999;">如需免费的前端网页托管,请开通 <a style="color: inherit;"
  149. href="https://unicloud.dcloud.net.cn">uniCloud</a> ,创建服务空间,并在 “前端网页托管”
  150. 里上传你的网页</span>
  151. </uni-forms-item>
  152. </uni-card>
  153. <uni-card :isShadow="false" v-if="isEdit">
  154. <text><text style="font-weight: bold;">提示:</text>保存后需重新生成发布页</text>
  155. </uni-card>
  156. <view class="uni-button-group">
  157. <button type="primary" class="uni-button" style="width: 100px;" @click="submit">保存</button>
  158. <navigator open-type="navigateBack" style="margin-left: 15px;">
  159. <button class="uni-button" style="width: 100px;">返回</button>
  160. </navigator>
  161. </view>
  162. </uni-forms>
  163. </view>
  164. </template>
  165. <script>
  166. import mixin from './mixin/publish_add_detail_mixin.js';
  167. const db = uniCloud.database();
  168. const dbCmd = db.command;
  169. const dbCollectionName = 'opendb-app-list';
  170. function randomString(len) {
  171. //设定要生成的字符串包含的字符
  172. var array = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  173. 'U', 'V', 'W', 'X', 'Y', 'Z'
  174. ];
  175. var result = '';
  176. for (var i = 0; i < len; i++) {
  177. result += array[Math.floor(Math.random() * 26)];
  178. }
  179. return result;
  180. }
  181. export default {
  182. mixins: [mixin],
  183. data() {
  184. return {
  185. mpExtra: ' ',
  186. mpAccordionStatus: 1,
  187. labelWidth: '80px'
  188. }
  189. },
  190. onLoad(e) {
  191. if (e.id) {
  192. this.isEdit = true
  193. uni.setNavigationBarTitle({
  194. title: '修改应用'
  195. })
  196. // this.formDataId = e.id
  197. this.setFormData('appid', e.id)
  198. this.getDetail(e.id)
  199. } else {
  200. // 填写应用名称后,给各平台设置相同的名称
  201. this.$watch('formData.name', (name) => {
  202. this.platFormKeys.forEach(key => {
  203. this.setFormData(`${key}.name`, name)
  204. })
  205. })
  206. }
  207. },
  208. onReady() {
  209. this.mpExtra = '折叠'
  210. },
  211. methods: {
  212. // 更新线上版本的 store 记录
  213. resolvestableVersionStoreList() {
  214. const modifiedMap = {}
  215. const modifiedKeys = []
  216. this.formData.store_list.forEach((item, index) => {
  217. modifiedKeys.push(item.id)
  218. modifiedMap[item.id] = index
  219. })
  220. return this.fetchAppInfo(this.getFormData('appid'), 'Android')
  221. .then(res => {
  222. if (!res.success) return
  223. if (res.store_list) {
  224. const originalMap = {}
  225. const originalKeys = []
  226. res.store_list.forEach((item, index) => {
  227. originalKeys.push(item.id)
  228. originalMap[item.id] = index
  229. })
  230. modifiedKeys.forEach((key, index) => {
  231. const afterItem = this.formData.store_list[modifiedMap[key]]
  232. // 新增
  233. if (originalKeys.indexOf(key) === -1) {
  234. res.store_list.push(afterItem)
  235. } else {
  236. // 修改
  237. res.store_list[originalMap[key]].name = afterItem.name
  238. res.store_list[originalMap[key]].scheme = afterItem.scheme
  239. }
  240. })
  241. // 删除
  242. for (let i = 0; i < res.store_list.length; i++) {
  243. let id = res.store_list[i].id
  244. if (this.deletedStore.indexOf(id) !== -1 && modifiedKeys.indexOf(id) === -1) {
  245. res.store_list.splice(i, 1)
  246. i--
  247. }
  248. }
  249. } else {
  250. res.store_list = this.formData.store_list
  251. }
  252. return this.updateAppVersion(res._id, {
  253. store_list: res.store_list
  254. })
  255. })
  256. },
  257. updateAppVersion(id, value) {
  258. return db.collection('opendb-app-versions').doc(id).update(value)
  259. },
  260. /**
  261. * 验证表单并提交
  262. */
  263. submit() {
  264. uni.showLoading({
  265. mask: true
  266. })
  267. this.formatFormData()
  268. this.$refs.form.validate(this.keepItems).then((res) => {
  269. return this.submitForm(res)
  270. }).catch((err) => {
  271. console.error(err)
  272. }).finally(() => {
  273. uni.hideLoading()
  274. })
  275. },
  276. /**
  277. * 提交表单
  278. */
  279. submitForm(value) {
  280. // 使用 clientDB 提交数据
  281. (
  282. this.isEdit ?
  283. this.requestCloudFunction('setNewAppData', {
  284. id: this.formDataId,
  285. value
  286. }) :
  287. db.collection(dbCollectionName).add(value)
  288. )
  289. .then((res) => {
  290. if (this.isEdit) return this.resolvestableVersionStoreList()
  291. })
  292. .then(() => {
  293. uni.showToast({
  294. title: `${this.isEdit ? '更新' : '新增'}成功`
  295. })
  296. this.getOpenerEventChannel().emit('refreshData')
  297. setTimeout(() => uni.navigateBack(), 500)
  298. })
  299. .catch((err) => {
  300. uni.showModal({
  301. content: err.message || '请求服务失败',
  302. showCancel: false
  303. })
  304. })
  305. },
  306. /**
  307. * 获取表单数据
  308. * @param {Object} id
  309. */
  310. getDetail(id) {
  311. uni.showLoading({
  312. mask: true
  313. })
  314. db.collection(dbCollectionName).where({
  315. appid: id
  316. }).get().then((res) => {
  317. const data = res.result.data[0]
  318. if (data) {
  319. this.formDataId = data._id
  320. this.initFormData(data)
  321. } else {
  322. this.autoFill()
  323. this.autoFillApp()
  324. }
  325. }).catch((err) => {
  326. uni.showModal({
  327. content: err.message || '请求服务失败',
  328. showCancel: false
  329. })
  330. }).finally(() => {
  331. uni.hideLoading()
  332. })
  333. },
  334. mpAccordion() {
  335. if (this.mpAccordionStatus) {
  336. this.mpExtra = '展开'
  337. this.mpAccordionStatus = 0
  338. } else {
  339. this.mpExtra = '折叠'
  340. this.mpAccordionStatus = 1
  341. }
  342. },
  343. addStoreScheme() {
  344. this.formData.store_list.push({
  345. enable: false,
  346. priority: 0,
  347. id: randomString(5) + '_' + Date.now()
  348. })
  349. },
  350. deleteStore(index, item) {
  351. if (item.scheme && item.scheme.trim().length && this.isEdit) {
  352. uni.showModal({
  353. content: '是否同步删除线上版本此条商店记录?',
  354. success: (res) => {
  355. const storeItem = this.formData.store_list.splice(index, 1)[0]
  356. if (storeItem && res.confirm) {
  357. this.deletedStore.push(storeItem.id)
  358. }
  359. }
  360. })
  361. } else {
  362. this.formData.store_list.splice(index, 1)[0]
  363. }
  364. },
  365. schemeDemo() {
  366. // #ifndef H5
  367. $refs.scheme.open('center')
  368. // #endif
  369. // #ifdef H5
  370. window.open("https://ask.dcloud.net.cn/article/39960", '_blank')
  371. // #endif
  372. }
  373. }
  374. }
  375. </script>
  376. <style lang="scss">
  377. .title_padding {
  378. padding-bottom: 15px;
  379. display: block;
  380. }
  381. .font_bold {
  382. font-weight: bold;
  383. }
  384. .uni-button-group {
  385. & button {
  386. margin-left: 15px;
  387. }
  388. & button:first-child {
  389. margin-left: 0px;
  390. }
  391. }
  392. ::v-deep {
  393. .forn-item__flex {
  394. .uni-forms-item__content {
  395. display: flex;
  396. align-items: center;
  397. .custom-button {
  398. height: 100%;
  399. margin-left: 10rpx;
  400. line-height: 36px;
  401. }
  402. }
  403. }
  404. .uni-card {
  405. padding: 0 !important;
  406. cursor: auto;
  407. }
  408. .uni-card__header {
  409. background-color: #eee;
  410. }
  411. .uni-card__header-title-text {
  412. font-weight: bold;
  413. }
  414. }
  415. .extra-button {
  416. display: flex;
  417. align-items: center;
  418. margin-bottom: 15px;
  419. button {
  420. margin: 0;
  421. }
  422. }
  423. .flex-center-r {
  424. display: flex;
  425. align-items: center;
  426. justify-content: center;
  427. }
  428. .tip {
  429. display: flex;
  430. flex-direction: column;
  431. align-items: flex-start;
  432. background-color: #f3f5f7;
  433. color: #2c3e50;
  434. padding: 10px;
  435. font-size: 32rpx;
  436. border: {
  437. color: #e96900;
  438. left-width: 8px;
  439. left-style: solid;
  440. }
  441. text {
  442. margin-right: 15px;
  443. }
  444. .custom-button {
  445. margin-left: 0px;
  446. }
  447. }
  448. .popup-content {
  449. padding: 30rpx;
  450. }
  451. ::v-deep .uni-file-picker__files {
  452. max-width: 100%;
  453. }
  454. </style>