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

360 lines
8.0 KiB

2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="视频分享" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <uv-form ref="form" :model="form" :rules="rules" labelPosition="left" labelWidth="340rpx" :labelStyle="{
  6. color: '#1B1B1B',
  7. fontSize: '32rpx',
  8. fontWeight: 'bold',
  9. }" errorType="toast">
  10. <view class="flex upload__view">
  11. <view class="upload upload-cover">
  12. <uv-form-item labelWidth="0" prop="indexImage">
  13. <formUpload v-model="form.indexImage">
  14. <template v-slot="{ value }">
  15. <!-- todo: 默认 -->
  16. <image :src="value" mode="aspectFill" style="width: 344rpx; height: 344rpx;"
  17. radius="14rpx" />
  18. </template>
  19. </formUpload>
  20. <view class="upload-cover-text flex">设置封面</view>
  21. </uv-form-item>
  22. </view>
  23. <view class="upload upload-video">
  24. <uv-form-item labelWidth="0" prop="vio">
  25. <formUpload v-model="form.vio" accept="video">
  26. <template v-slot>
  27. <video v-if="form.vio" :src="form.vio" style="width: 344rpx; height: 344rpx;"
  28. radius="14rpx" :controls="false" :autoplay="false"
  29. :show-center-play-btn="false"></video>
  30. <view v-else class="flex flex-column" style="width: 344rpx; height: 344rpx;">
  31. <image src="../static/record/icon-camera.png"
  32. style="width: 130rpx; height: 105rpx;"></image>
  33. <text class="upload-video-text">上传视频</text>
  34. </view>
  35. </template>
  36. </formUpload>
  37. </uv-form-item>
  38. </view>
  39. </view>
  40. <view class="form-item">
  41. <uv-form-item label="标题" labelWidth="84rpx" prop="headTitle">
  42. <view class="form-item-content">
  43. <formInput v-model="form.headTitle" placeholder="请输入你的视频名称" width="584rpx"></formInput>
  44. </view>
  45. </uv-form-item>
  46. </view>
  47. <view class="form-item">
  48. <uv-form-item label="设置广告弹出时间(s)" prop="timeNum">
  49. <view class="form-item-content">
  50. <formNumberBox v-model="form.timeNum"></formNumberBox>
  51. </view>
  52. </uv-form-item>
  53. </view>
  54. <view class="form-item">
  55. <uv-form-item label="设置转发次数(次)" prop="num">
  56. <view class="form-item-content">
  57. <formNumberBox v-model="form.num"></formNumberBox>
  58. </view>
  59. </uv-form-item>
  60. </view>
  61. <view class="form-item">
  62. <uv-form-item label="选择二维码" prop="wxCodeImage">
  63. <view class="form-item-content">
  64. <formUpload v-model="form.wxCodeImage">
  65. <template v-slot="{ value }">
  66. <view class="flex" style="min-width: 93rpx; height: 45rpx;">
  67. <image :src="value" mode="aspectFill" style="width: 45rpx; height: 45rpx;"
  68. radius="14rpx" />
  69. <uv-icon style="margin-left: 20rpx" name="arrow-right" color="#000000"
  70. size="28rpx"></uv-icon>
  71. </view>
  72. </template>
  73. </formUpload>
  74. </view>
  75. </uv-form-item>
  76. </view>
  77. <view class="form-item">
  78. <uv-form-item label="视频描述" prop="textDetails" labelPosition="top">
  79. <view style="margin-top: 32rpx;">
  80. <formTextarea v-model="form.textDetails" placeholder="请描述你的视频"></formTextarea>
  81. </view>
  82. </uv-form-item>
  83. </view>
  84. </uv-form>
  85. </view>
  86. <!-- 审核通过 -->
  87. <button v-if="status === 1" class="button-submit" open-type="share">
  88. 发布
  89. </button>
  90. <!-- 不是 审核中 已发布 -> 创建分享 审核不通过 -->
  91. <button v-else-if="![0,1].includes(status)" class="button-submit" @click="preSubmit">
  92. 提交审核
  93. </button>
  94. <autoCrop ref="autoCropRef" @change="onSubmit"></autoCrop>
  95. </view>
  96. </template>
  97. <script>
  98. import {
  99. mapState
  100. } from 'vuex'
  101. import shareLog from '@/utils/shareLog'
  102. import formUpload from '../components/formUpload.vue'
  103. import formInput from '../components/formInput.vue'
  104. import formNumberBox from '../components/formNumberBox.vue'
  105. import formTextarea from '../components/formTextarea.vue'
  106. import autoCrop from '../components/autoCrop.vue'
  107. export default {
  108. components: {
  109. formUpload,
  110. formInput,
  111. formNumberBox,
  112. formTextarea,
  113. autoCrop,
  114. },
  115. data() {
  116. return {
  117. id: null,
  118. status: null,
  119. form: {
  120. headTitle: null,
  121. indexImage: null,
  122. vio: null,
  123. timeNum: 0,
  124. num: 0,
  125. wxCodeImage: null,
  126. textDetails: null,
  127. },
  128. rules: {
  129. 'indexImage': {
  130. type: 'string',
  131. required: true,
  132. message: '请设置封面',
  133. },
  134. 'vio': {
  135. type: 'string',
  136. required: true,
  137. message: '请上传视频',
  138. },
  139. 'headTitle': {
  140. type: 'string',
  141. required: true,
  142. message: '请输入你的视频名称',
  143. },
  144. 'timeNum': {
  145. type: 'number',
  146. required: true,
  147. message: '请设置广告弹出时间(大于1)',
  148. validator: (rule, value, callback) => {
  149. if (value > 1) {
  150. return true
  151. }
  152. return false;
  153. },
  154. },
  155. 'num': {
  156. type: 'number',
  157. required: true,
  158. message: '请设置转发次数(大于0)',
  159. validator: (rule, value, callback) => {
  160. if (value > 0) {
  161. return true
  162. }
  163. return false;
  164. },
  165. },
  166. 'wxCodeImage': {
  167. type: 'string',
  168. required: true,
  169. message: '请选择二维码',
  170. },
  171. 'textDetails': {
  172. type: 'string',
  173. required: true,
  174. message: '请描述你的视频',
  175. },
  176. },
  177. }
  178. },
  179. computed: {
  180. ...mapState(['userInfo']),
  181. },
  182. onLoad(option) {
  183. const {
  184. id
  185. } = option
  186. if (!id) {
  187. return
  188. }
  189. this.id = id
  190. this.fetchDetails(id)
  191. },
  192. onReady() {
  193. this.$refs.form.setRules(this.rules);
  194. },
  195. onShareAppMessage(res) {
  196. const {
  197. headTitle,
  198. indexImage,
  199. } = this.form
  200. let o = {
  201. title: headTitle,
  202. imageUrl: indexImage,
  203. path: `/pages_order/sharing/video?id=${this.id}&state=1&shareId=${this.userInfo.id}`
  204. }
  205. //调用增加分享次数的方法
  206. const params = {
  207. id: this.id,
  208. state: "1",
  209. }
  210. this.$fetch('addLogShareInfo', params)
  211. // todo: get times and check is unlocked
  212. shareLog.insert(this.id)
  213. this.isLocked = false
  214. return o
  215. },
  216. methods: {
  217. async fetchDetails(id) {
  218. try {
  219. const result = await this.$fetch('getVideoShareInfo', {
  220. id
  221. })
  222. const {
  223. headTitle,
  224. indexImage,
  225. vio,
  226. timeNum,
  227. num,
  228. wxCodeImage,
  229. textDetails,
  230. status,
  231. } = result || {}
  232. this.form = {
  233. headTitle,
  234. indexImage,
  235. vio,
  236. timeNum,
  237. num,
  238. wxCodeImage,
  239. textDetails,
  240. }
  241. this.status = status
  242. } catch (err) {
  243. }
  244. },
  245. async preSubmit() {
  246. try {
  247. await this.$refs.form.validate()
  248. this.$refs.autoCropRef.set(this.form.indexImage)
  249. } catch (err) {
  250. }
  251. },
  252. async onSubmit(indexImage) {
  253. try {
  254. await this.$refs.form.validate()
  255. const {
  256. headTitle,
  257. vio,
  258. timeNum,
  259. num,
  260. wxCodeImage,
  261. textDetails,
  262. } = this.form
  263. const params = {
  264. headTitle,
  265. indexImage,
  266. vio,
  267. timeNum,
  268. num,
  269. wxCodeImage,
  270. textDetails,
  271. }
  272. if (this.id) {
  273. params.id = this.id
  274. }
  275. await this.$fetch('saveOrUpdateVideoShare', params)
  276. uni.showToast({
  277. title: '提交成功',
  278. icon: 'none'
  279. })
  280. setTimeout(uni.navigateBack, 1000, -1)
  281. } catch (err) {
  282. }
  283. },
  284. onPublish() {
  285. // todo
  286. },
  287. }
  288. }
  289. </script>
  290. <style scoped lang="scss">
  291. @import '../styles/pageForm.scss';
  292. .upload__view {
  293. justify-content: space-between;
  294. margin-bottom: 20rpx;
  295. }
  296. .upload {
  297. background-color: $uni-fg-color;
  298. border-radius: 12rpx;
  299. overflow: hidden;
  300. /deep/ .uv-form-item__body {
  301. padding: 0 !important;
  302. }
  303. }
  304. .upload-video {
  305. &-text {
  306. color: #1B1B1B;
  307. font-size: 32rpx;
  308. font-weight: 700;
  309. margin-top: 35rpx;
  310. }
  311. }
  312. .upload-cover {
  313. position: relative;
  314. &-text {
  315. position: absolute;
  316. bottom: 0;
  317. width: 100%;
  318. background-color: rgba($color: #000000, $alpha: 0.6);
  319. color: #FFFFFF;
  320. padding: 21rpx 0;
  321. }
  322. }
  323. </style>