uni-portal.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="uni-container">
  3. <h3 class="text-separated" style="padding: 0 0 20rpx 0;">步骤1:了解“统一发布页”</h3>
  4. <view style="margin-top: 20rpx;">
  5. <view class="text-separated">
  6. <text class="strong">uni-portal </text>
  7. <text>是 uni-app 提供的一套开箱即用的“统一发布页”。</text>
  8. </view>
  9. <view class="text-separated">
  10. <text class="strong">uni-portal </text>
  11. <text>可作为面向用户的统一业务名片,在一个页面集中展现:App下载地址、小程序二维码、H5访问链接等信息。</text>
  12. </view>
  13. <!-- #ifdef H5 -->
  14. <view class="text-separated">
  15. <text style="font-size: 16px;">uni-app 官方示例的发布页就是基于<text class="strong">uni-portal </text> 制作的,<a
  16. href="https://hellouniapp.dcloud.net.cn/portal" target="_blank" class="a-label">点击体验</a>
  17. </text>
  18. </view>
  19. <!-- #endif -->
  20. </view>
  21. <h3 class="text-separated" style="padding: 40rpx 0 20rpx 0;">步骤2:获取“统一发布页”</h3>
  22. <view class="flex text-separated" style="margin-top: 20rpx;">
  23. <text>
  24. <view class="strong">uni-portal </view> 可根据「应用管理」中所填写的应用信息,一键生成发布页:
  25. </text>
  26. <button class="custom-button" size="mini" type="primary" @click="publish"
  27. style="margin: 0;">生成并下载发布页</button>
  28. </view>
  29. <h3 class="text-separated" style="padding: 40rpx 0 20rpx 0;">步骤3:上传“统一发布页”</h3>
  30. <view style="margin-top: 20rpx;">
  31. <view class="text-separated">
  32. <text>
  33. 步骤2下载的“统一发布页”,是一个静态HTML页面,你可以直接在本地浏览器中打开访问。
  34. </text>
  35. </view>
  36. <view class="text-separated">
  37. <text>
  38. 为了让用户访问到这个“统一发布页”,你需要将该静态HTML文件上传到你的服务器中;推荐使用<a href="https://uniapp.dcloud.io/uniCloud/hosting"
  39. target="_blank" class="a-label" style="padding: 5px;">前端网页托管</a>,因为前端网页托管具备使用更简单、价格更便宜、访问更快等优点。
  40. </text>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. const download = function(content, filename) {
  47. let eleLink = document.createElement('a');
  48. eleLink.download = filename;
  49. eleLink.style.display = 'none';
  50. let blob = new Blob([content]);
  51. eleLink.href = URL.createObjectURL(blob);
  52. document.body.appendChild(eleLink);
  53. eleLink.click();
  54. document.body.removeChild(eleLink);
  55. };
  56. export default {
  57. data() {
  58. return {
  59. id: ''
  60. }
  61. },
  62. onLoad({
  63. id
  64. }) {
  65. this.id = id
  66. },
  67. methods: {
  68. publish() {
  69. if (!this.id) {
  70. uni.showModal({
  71. content: '页面出错,请返回重进',
  72. showCancel: false,
  73. success(res) {
  74. uni.redirectTo({
  75. url: '/pages/system/app/list'
  76. })
  77. }
  78. })
  79. return
  80. }
  81. this.$request('createPublishHtml', {
  82. id: this.id
  83. }, {
  84. functionName: 'uni-portal',
  85. showModal: false
  86. }).then(res => {
  87. // #ifdef H5
  88. if ('download' in document.createElement('a')) {
  89. download(res.body, 'index.html');
  90. } else {
  91. uni.showToast({
  92. icon: 'error',
  93. title: '浏览器不支持',
  94. duration: 800
  95. })
  96. }
  97. // #endif
  98. }).catch((res) => {
  99. uni.showModal({
  100. content: res.errMsg,
  101. showCancel: false
  102. })
  103. })
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss">
  109. .strong {
  110. padding: 10rpx;
  111. display: inline-block;
  112. color: #c7254e;
  113. }
  114. .a-label {
  115. text-decoration: none;
  116. color: #0366d6;
  117. font-weight: bold;
  118. padding: 10rpx;
  119. }
  120. .text-separated {
  121. line-height: 2em;
  122. color: #2c3e50;
  123. }
  124. .tip {
  125. display: flex;
  126. flex-direction: column;
  127. align-items: flex-start;
  128. background-color: #f3f5f7;
  129. color: #2c3e50;
  130. padding: 10px;
  131. font-size: 32rpx;
  132. border: {
  133. color: #409EFF;
  134. left-width: 8px;
  135. left-style: solid;
  136. }
  137. text {
  138. margin-right: 15px;
  139. }
  140. .custom-button {
  141. margin-left: 0px;
  142. }
  143. }
  144. </style>