裂变星小程序-25.03.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
7.1 KiB

  1. <template>
  2. <view class="page">
  3. <navbar title="文章分享" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <uv-form
  6. ref="form"
  7. :model="form"
  8. :rules="rules"
  9. labelPosition="left"
  10. labelWidth="300rpx"
  11. :labelStyle="{
  12. color: '#1B1B1B',
  13. fontSize: '32rpx',
  14. fontWeight: 'bold',
  15. }"
  16. >
  17. <view class="form-item">
  18. <uv-form-item label="用户ID" prop="id">
  19. <view class="form-item-content">
  20. <template v-if="form.id">
  21. <text>{{ form.id }}</text>
  22. <view style="margin-left: 20rpx;">
  23. <button class="btn-simple" plain @click="$utils.copyText(form.id)">
  24. <uv-icon name="file-text" color="#05D9A2" size="28rpx"></uv-icon>
  25. </button>
  26. </view>
  27. </template>
  28. </view>
  29. </uv-form-item>
  30. </view>
  31. <view class="form-item">
  32. <uv-form-item label="选择封面图" prop="imageUrl">
  33. <view class="form-item-content">
  34. <formUpload v-model="form.imageUrl">
  35. <template v-slot="{ value }">
  36. <view class="flex" style="min-width: 116rpx; height: 45rpx;">
  37. <image
  38. :src="value"
  39. mode="aspectFill"
  40. style="width: 68rpx; height: 68rpx;"
  41. radius="14rpx"
  42. />
  43. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  44. </view>
  45. </template>
  46. </formUpload>
  47. </view>
  48. </uv-form-item>
  49. </view>
  50. <view class="form-item">
  51. <uv-form-item label="标题" labelWidth="84rpx" prop="title">
  52. <view class="form-item-content">
  53. <formInput v-model="form.title" placeholder="请输入你的文章标题" width="584rpx"></formInput>
  54. </view>
  55. </uv-form-item>
  56. </view>
  57. <view class="form-item">
  58. <uv-form-item label="设置转发次数(次)" prop="times">
  59. <view class="form-item-content">
  60. <formNumberBox v-model="form.times" ></formNumberBox>
  61. </view>
  62. </uv-form-item>
  63. </view>
  64. <view class="form-item">
  65. <uv-form-item label="选择二维码" prop="qrCode">
  66. <view class="form-item-content">
  67. <formUpload v-model="form.qrCode">
  68. <template v-slot="{ value }">
  69. <view class="flex" style="min-width: 93rpx; height: 45rpx;">
  70. <image
  71. :src="value"
  72. mode="aspectFill"
  73. style="width: 45rpx; height: 45rpx;"
  74. radius="14rpx"
  75. />
  76. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  77. </view>
  78. </template>
  79. </formUpload>
  80. </view>
  81. </uv-form-item>
  82. </view>
  83. <view class="form-item">
  84. <uv-form-item label="文章内容" prop="description" labelPosition="top">
  85. <view class="editor__view" style="margin-top: 32rpx;">
  86. <editor id="editor" class="editor"
  87. placeholder="请输入你的文章内容"
  88. @ready="onEditorReady"
  89. @input="onEditroInput"
  90. ></editor>
  91. <view class="flex editor-tools">
  92. <view style="flex: 1;">
  93. <button @click="insertImage" plain class="btn-simple" style="float: left; font-size: 0;">
  94. <image src="../static/record/icon-add.png" style="width: 126rpx; height: 126rpx;" ></image>
  95. </button>
  96. </view>
  97. <view style="flex: 1; text-align: right;">
  98. <text class="editor-count">{{ `${descLen}/${descLengthLimit}` }}</text>
  99. </view>
  100. </view>
  101. </view>
  102. </uv-form-item>
  103. </view>
  104. </uv-form>
  105. </view>
  106. <!-- 审核通过 -->
  107. <button v-if="auditStatus === 1" class="button-submit" @click="onPublish">
  108. 发布
  109. </button>
  110. <!-- 不是 审核中 已发布 -> 创建分享 审核不通过 -->
  111. <button v-else-if="![0,2].includes(auditStatus)" class="button-submit" @click="onSubmit">
  112. 提交审核
  113. </button>
  114. </view>
  115. </template>
  116. <script>
  117. import formInput from '../components/formInput.vue'
  118. import formNumberBox from '../components/formNumberBox.vue'
  119. import formUpload from '../components/formUpload.vue'
  120. import formTextarea from '../components/formTextarea.vue'
  121. export default {
  122. components: {
  123. formInput,
  124. formNumberBox,
  125. formUpload,
  126. formTextarea,
  127. },
  128. data() {
  129. return {
  130. id: null,
  131. auditStatus: null,
  132. form: {
  133. id: null,
  134. imageUrl: null,
  135. title: null,
  136. times: 10,
  137. qrCode: null,
  138. description: null,
  139. },
  140. rules: {
  141. // todo
  142. },
  143. editorCtx: null,
  144. descLen: 0,
  145. descLengthLimit: 1000,
  146. }
  147. },
  148. onLoad(option) {
  149. const { id } = option
  150. this.id = id
  151. // todo: init data by id
  152. },
  153. methods: {
  154. onEditorReady() {
  155. uni.createSelectorQuery().select('#editor').context((res) => {
  156. this.editorCtx = res.context
  157. }).exec()
  158. },
  159. onEditroInput(e) {
  160. const { text } = e.detail
  161. this.descLen = text?.length || 0
  162. },
  163. insertImage() {
  164. uni.chooseImage({
  165. count: 1,
  166. success: (res) => {
  167. // this.editorCtx.insertImage({
  168. // src: res.tempFilePaths[0],
  169. // alt: '图像',
  170. // })
  171. // todo: check
  172. this.$Oss.ossUpload(res.tempFilePaths[0]).then(url => {
  173. this.editorCtx.insertImage({
  174. src: url,
  175. alt: '图像',
  176. })
  177. })
  178. }
  179. })
  180. },
  181. getEditroContents() {
  182. return new Promise((resolve, reject) => {
  183. this.editorCtx.getContents({
  184. success: (e) => {
  185. const { html, text } = e
  186. resolve({ html, text })
  187. },
  188. fail: () => {
  189. reject()
  190. }
  191. })
  192. })
  193. },
  194. async onSubmit() {
  195. try {
  196. const description = (await this.getEditroContents())?.html
  197. // todo: decode?
  198. console.log(description)
  199. return
  200. const params = { ...this.form, description }
  201. // todo
  202. this.$api('submitPersonalSharing', params)
  203. } catch (err) {
  204. }
  205. },
  206. onPublish() {
  207. // todo
  208. },
  209. }
  210. }
  211. </script>
  212. <style scoped lang="scss">
  213. @import '../styles/pageForm.scss';
  214. .editor__view {
  215. background-color: #F3F3F3;
  216. border-radius: 12rpx;
  217. }
  218. .editor {
  219. height: 253rpx;
  220. padding: 20rpx;
  221. &-tools {
  222. align-items: flex-end;
  223. padding: 0 20rpx 16rpx 14rpx;
  224. }
  225. &-count {
  226. color: #999999;
  227. font-size: 28rpx;
  228. }
  229. }
  230. </style>