裂变星小程序-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.

244 lines
6.9 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. <button v-if="auditStatus === 1" class="button-submit" @click="onPublish">
  107. 发布
  108. </button>
  109. <button v-else-if="auditStatus !== 0" class="button-submit" @click="onSubmit">
  110. 提交审核
  111. </button>
  112. </view>
  113. </template>
  114. <script>
  115. import formInput from '../components/formInput.vue'
  116. import formNumberBox from '../components/formNumberBox.vue'
  117. import formUpload from '../components/formUpload.vue'
  118. import formTextarea from '../components/formTextarea.vue'
  119. export default {
  120. components: {
  121. formInput,
  122. formNumberBox,
  123. formUpload,
  124. formTextarea,
  125. },
  126. data() {
  127. return {
  128. id: null,
  129. auditStatus: null,
  130. form: {
  131. id: null,
  132. imageUrl: null,
  133. title: null,
  134. times: 10,
  135. qrCode: null,
  136. description: null,
  137. },
  138. rules: {
  139. // todo
  140. },
  141. editorCtx: null,
  142. descLen: 0,
  143. descLengthLimit: 1000,
  144. }
  145. },
  146. onLoad(option) {
  147. const { id } = option
  148. this.id = id
  149. // todo: init data by id
  150. },
  151. methods: {
  152. onEditorReady() {
  153. uni.createSelectorQuery().select('#editor').context((res) => {
  154. this.editorCtx = res.context
  155. }).exec()
  156. },
  157. onEditroInput(e) {
  158. const { text } = e.detail
  159. this.descLen = text?.length || 0
  160. },
  161. insertImage() {
  162. uni.chooseImage({
  163. count: 1,
  164. success: (res) => {
  165. // this.editorCtx.insertImage({
  166. // src: res.tempFilePaths[0],
  167. // alt: '图像',
  168. // })
  169. // todo: check
  170. this.$Oss.ossUpload(res.tempFilePaths[0]).then(url => {
  171. this.editorCtx.insertImage({
  172. src: url,
  173. alt: '图像',
  174. })
  175. })
  176. }
  177. })
  178. },
  179. getEditroContents() {
  180. return new Promise((resolve, reject) => {
  181. this.editorCtx.getContents({
  182. success: (e) => {
  183. const { html, text } = e
  184. resolve({ html, text })
  185. },
  186. fail: () => {
  187. reject()
  188. }
  189. })
  190. })
  191. },
  192. async onSubmit() {
  193. try {
  194. const description = (await this.getEditroContents())?.html
  195. // todo: decode?
  196. const params = { ...this.form, description }
  197. // todo
  198. this.$api('submitPersonalSharing', params)
  199. } catch (err) {
  200. }
  201. },
  202. onPublish() {
  203. // todo
  204. },
  205. }
  206. }
  207. </script>
  208. <style scoped lang="scss">
  209. @import '../styles/pageForm.scss';
  210. .editor__view {
  211. background-color: #F3F3F3;
  212. border-radius: 12rpx;
  213. }
  214. .editor {
  215. height: 253rpx;
  216. padding: 20rpx;
  217. &-tools {
  218. align-items: flex-end;
  219. padding: 0 20rpx 16rpx 14rpx;
  220. }
  221. &-count {
  222. color: #999999;
  223. font-size: 28rpx;
  224. }
  225. }
  226. </style>