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

340 lines
8.7 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. errorType="toast"
  17. >
  18. <view class="form-item">
  19. <uv-form-item label="用户ID" prop="userId">
  20. <view class="form-item-content">
  21. <text>{{ userId }}</text>
  22. <view style="margin-left: 20rpx;">
  23. <button class="btn-simple" plain @click="$utils.copyText(userId)">
  24. <uv-icon name="file-text" color="#05D9A2" size="28rpx"></uv-icon>
  25. </button>
  26. </view>
  27. </view>
  28. </uv-form-item>
  29. </view>
  30. <view class="form-item">
  31. <uv-form-item label="选择头像" prop="headImage">
  32. <view class="form-item-content">
  33. <button
  34. class="btn-avatar"
  35. :plain="true"
  36. :hairline="false"
  37. open-type="chooseAvatar"
  38. @chooseavatar="onChooseAvatar"
  39. >
  40. <image
  41. :src="form.headImage || '../static/auth/avatar.png'"
  42. style="width: 68rpx; height: 68rpx;"
  43. mode=""
  44. ></image>
  45. </button>
  46. </view>
  47. </uv-form-item>
  48. </view>
  49. <view class="form-item">
  50. <uv-form-item label="昵称" labelWidth="105rpx" prop="headTitle">
  51. <view class="form-item-content">
  52. <formInput v-model="form.headTitle" placeholder="请输入你的昵称" width="540rpx"></formInput>
  53. </view>
  54. </uv-form-item>
  55. </view>
  56. <view class="form-item">
  57. <uv-form-item label="选择封面图" prop="indexImage">
  58. <view class="form-item-content">
  59. <formUpload v-model="form.indexImage">
  60. <template v-slot="{ value }">
  61. <view class="flex" style="min-width: 116rpx; height: 45rpx;">
  62. <image
  63. :src="value"
  64. mode="aspectFill"
  65. style="width: 68rpx; height: 68rpx;"
  66. radius="14rpx"
  67. />
  68. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  69. </view>
  70. </template>
  71. </formUpload>
  72. </view>
  73. </uv-form-item>
  74. </view>
  75. <view class="form-item">
  76. <uv-form-item label="设置转发次数(次)" prop="num">
  77. <view class="form-item-content">
  78. <formNumberBox v-model="form.num" ></formNumberBox>
  79. </view>
  80. </uv-form-item>
  81. </view>
  82. <view class="form-item">
  83. <uv-form-item label="选择二维码" prop="wxCodeImage">
  84. <view class="form-item-content">
  85. <formUpload v-model="form.wxCodeImage">
  86. <template v-slot="{ value }">
  87. <view class="flex" style="min-width: 93rpx; height: 45rpx;">
  88. <image
  89. :src="value"
  90. mode="aspectFill"
  91. style="width: 45rpx; height: 45rpx;"
  92. radius="14rpx"
  93. />
  94. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000" size="28rpx"></uv-icon>
  95. </view>
  96. </template>
  97. </formUpload>
  98. </view>
  99. </uv-form-item>
  100. </view>
  101. <view class="form-item">
  102. <uv-form-item label="文案描述" prop="textDetails" labelPosition="top">
  103. <view style="margin-top: 32rpx;">
  104. <formTextarea
  105. v-model="form.textDetails"
  106. placeholder="请输入你的文案"
  107. ></formTextarea>
  108. </view>
  109. </uv-form-item>
  110. </view>
  111. </uv-form>
  112. </view>
  113. <!-- 审核通过 -->
  114. <button v-if="status === 1" class="button-submit" open-type="share">
  115. 发布
  116. </button>
  117. <!-- 不是 审核中 已发布 -> 创建分享 审核不通过 -->
  118. <button v-else-if="![0,1].includes(status)" class="button-submit" @click="onSubmit">
  119. 提交审核
  120. </button>
  121. </view>
  122. </template>
  123. <script>
  124. import { mapState } from 'vuex'
  125. import formInput from '../components/formInput.vue'
  126. import formNumberBox from '../components/formNumberBox.vue'
  127. import formUpload from '../components/formUpload.vue'
  128. import formTextarea from '../components/formTextarea.vue'
  129. export default {
  130. components: {
  131. formInput,
  132. formNumberBox,
  133. formUpload,
  134. formTextarea,
  135. },
  136. data() {
  137. return {
  138. id: null,
  139. status: null,
  140. form: {
  141. userId: null,
  142. headImage: null,
  143. headTitle: null,
  144. indexImage: null,
  145. num: 0,
  146. wxCodeImage: null,
  147. textDetails: null,
  148. },
  149. rules: {
  150. 'headImage': {
  151. type: 'string',
  152. required: true,
  153. message: '请选择头像',
  154. },
  155. 'headTitle': {
  156. type: 'string',
  157. required: true,
  158. message: '请输入你的昵称',
  159. },
  160. 'indexImage': {
  161. type: 'string',
  162. required: true,
  163. message: '请选择封面图',
  164. },
  165. 'num': {
  166. type: 'number',
  167. required: true,
  168. message: '请设置转发次数(大于1)',
  169. validator: (rule, value, callback) => {
  170. if (value > 1) {
  171. return true
  172. }
  173. return false;
  174. },
  175. },
  176. 'wxCodeImage': {
  177. type: 'string',
  178. required: true,
  179. message: '请选择二维码',
  180. },
  181. 'textDetails': {
  182. type: 'string',
  183. required: true,
  184. message: '请输入你的文案',
  185. },
  186. },
  187. }
  188. },
  189. computed: {
  190. ...mapState(['userInfo']),
  191. userId() {
  192. return this.form.userId || this.userInfo?.id
  193. },
  194. disabled() {
  195. // todo
  196. return ![0, 1].includes(this.status)
  197. }
  198. },
  199. onLoad(option) {
  200. const { id } = option
  201. if (!id) {
  202. return
  203. }
  204. this.id = id
  205. this.fetchDetails(id)
  206. },
  207. onReady() {
  208. this.$refs.form.setRules(this.rules);
  209. },
  210. onShareAppMessage(res) {
  211. const {
  212. headTitle,
  213. indexImage,
  214. } = this.form
  215. let o = {
  216. title : headTitle,
  217. imageUrl: indexImage,
  218. path: `/pages_order/sharing/personal?id=${this.id}&state=0&shareId=${this.userInfo.id}`
  219. }
  220. this.isLocked = false
  221. return o
  222. },
  223. methods: {
  224. onChooseAvatar(res) {
  225. this.$Oss.ossUpload(res.target.avatarUrl)
  226. .then(url => {
  227. this.form.headImage = url
  228. })
  229. },
  230. async fetchDetails(id) {
  231. try {
  232. const result = await this.$fetch('getShareInfo', { id })
  233. const {
  234. userId,
  235. headImage,
  236. headTitle,
  237. indexImage,
  238. num,
  239. wxCodeImage,
  240. textDetails,
  241. status,
  242. } = result || {}
  243. this.form = {
  244. userId,
  245. headImage,
  246. headTitle,
  247. indexImage,
  248. num,
  249. wxCodeImage,
  250. textDetails,
  251. }
  252. this.status = status
  253. } catch (err) {
  254. }
  255. },
  256. async onSubmit() {
  257. try {
  258. await this.$refs.form.validate()
  259. const {
  260. headImage,
  261. headTitle,
  262. indexImage,
  263. num,
  264. wxCodeImage,
  265. textDetails,
  266. } = this.form
  267. const params = {
  268. userId: this.userId,
  269. headImage,
  270. headTitle,
  271. indexImage,
  272. num,
  273. wxCodeImage,
  274. textDetails,
  275. }
  276. if (this.id) {
  277. params.id = this.id
  278. }
  279. await this.$fetch('saveOrUpdateShare', params)
  280. uni.showToast({
  281. title: '提交成功',
  282. icon: 'none'
  283. })
  284. setTimeout(uni.navigateBack, 1000, -1)
  285. } catch (err) {
  286. }
  287. },
  288. }
  289. }
  290. </script>
  291. <style scoped lang="scss">
  292. @import '../styles/pageForm.scss';
  293. .btn-avatar {
  294. background: transparent;
  295. border: none;
  296. border-radius: none;
  297. box-shadow: none;
  298. padding: 0;
  299. margin: 0;
  300. font-size: 0;
  301. text-align: right;
  302. }
  303. .button-submit {
  304. margin: 0;
  305. position: fixed;
  306. bottom: 138rpx;
  307. left: 20rpx;
  308. width: calc(100% - 40rpx);
  309. height: 90rpx;
  310. }
  311. </style>