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

375 lines
9.4 KiB

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