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

378 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 shareLog from '@/utils/shareLog'
  122. import formUpload from '../components/formUpload.vue'
  123. import formInput from '../components/formInput.vue'
  124. import formNumberBox from '../components/formNumberBox.vue'
  125. import formTextarea from '../components/formTextarea.vue'
  126. import autoCrop from '../components/autoCrop.vue'
  127. export default {
  128. components: {
  129. formUpload,
  130. formInput,
  131. formNumberBox,
  132. formTextarea,
  133. autoCrop,
  134. },
  135. data() {
  136. return {
  137. id: null,
  138. status: null,
  139. form: {
  140. headTitle: null,
  141. indexImage: null,
  142. vio: null,
  143. timeNum: 0,
  144. num: 0,
  145. wxCodeImage: null,
  146. textDetails: null,
  147. },
  148. rules: {
  149. 'indexImage': {
  150. type: 'string',
  151. required: true,
  152. message: '请设置封面',
  153. },
  154. 'vio': {
  155. type: 'string',
  156. required: true,
  157. message: '请上传视频',
  158. },
  159. 'headTitle': {
  160. type: 'string',
  161. required: true,
  162. message: '请输入你的视频名称',
  163. },
  164. 'timeNum': {
  165. type: 'number',
  166. required: true,
  167. message: '请设置广告弹出时间(大于1)',
  168. validator: (rule, value, callback) => {
  169. if (value > 1) {
  170. return true
  171. }
  172. return false;
  173. },
  174. },
  175. 'num': {
  176. type: 'number',
  177. required: true,
  178. message: '请设置转发次数(大于0)',
  179. validator: (rule, value, callback) => {
  180. if (value > 0) {
  181. return true
  182. }
  183. return false;
  184. },
  185. },
  186. 'wxCodeImage': {
  187. type: 'string',
  188. required: true,
  189. message: '请选择二维码',
  190. },
  191. 'textDetails': {
  192. type: 'string',
  193. required: true,
  194. message: '请描述你的视频',
  195. },
  196. },
  197. }
  198. },
  199. computed: {
  200. ...mapState(['userInfo']),
  201. },
  202. onLoad(option) {
  203. const { id } = option
  204. if (!id) {
  205. return
  206. }
  207. this.id = id
  208. this.fetchDetails(id)
  209. },
  210. onReady() {
  211. this.$refs.form.setRules(this.rules);
  212. },
  213. onShareAppMessage(res) {
  214. const {
  215. headTitle,
  216. indexImage,
  217. } = this.form
  218. let o = {
  219. title : headTitle,
  220. imageUrl: indexImage,
  221. path: `/pages_order/sharing/video?id=${this.id}&state=1&shareId=${this.userInfo.id}`
  222. }
  223. //调用增加分享次数的方法
  224. const params = {
  225. id:this.id,
  226. state:"1",
  227. }
  228. this.$fetch('addLogShareInfo', params)
  229. // todo: get times and check is unlocked
  230. shareLog.insert(this.id)
  231. this.isLocked = false
  232. return o
  233. },
  234. methods: {
  235. async fetchDetails(id) {
  236. try {
  237. const result = await this.$fetch('getVideoShareInfo', { id })
  238. const {
  239. headTitle,
  240. indexImage,
  241. vio,
  242. timeNum,
  243. num,
  244. wxCodeImage,
  245. textDetails,
  246. status,
  247. } = result || {}
  248. this.form = {
  249. headTitle,
  250. indexImage,
  251. vio,
  252. timeNum,
  253. num,
  254. wxCodeImage,
  255. textDetails,
  256. }
  257. this.status = status
  258. } catch (err) {
  259. }
  260. },
  261. async preSubmit() {
  262. try {
  263. await this.$refs.form.validate()
  264. this.$refs.autoCropRef.set(this.form.indexImage)
  265. } catch (err) {
  266. }
  267. },
  268. async onSubmit(indexImage) {
  269. try {
  270. await this.$refs.form.validate()
  271. const {
  272. headTitle,
  273. vio,
  274. timeNum,
  275. num,
  276. wxCodeImage,
  277. textDetails,
  278. } = this.form
  279. const params = {
  280. headTitle,
  281. indexImage,
  282. vio,
  283. timeNum,
  284. num,
  285. wxCodeImage,
  286. textDetails,
  287. }
  288. if (this.id) {
  289. params.id = this.id
  290. }
  291. await this.$fetch('saveOrUpdateVideoShare', params)
  292. uni.showToast({
  293. title: '提交成功',
  294. icon: 'none'
  295. })
  296. setTimeout(uni.navigateBack, 1000, -1)
  297. } catch (err) {
  298. }
  299. },
  300. onPublish() {
  301. // todo
  302. },
  303. }
  304. }
  305. </script>
  306. <style scoped lang="scss">
  307. @import '../styles/pageForm.scss';
  308. .upload__view {
  309. justify-content: space-between;
  310. margin-bottom: 20rpx;
  311. }
  312. .upload {
  313. background-color: $uni-fg-color;
  314. border-radius: 12rpx;
  315. overflow: hidden;
  316. /deep/ .uv-form-item__body {
  317. padding: 0 !important;
  318. }
  319. }
  320. .upload-video {
  321. &-text {
  322. color: #1B1B1B;
  323. font-size: 32rpx;
  324. font-weight: 700;
  325. margin-top: 35rpx;
  326. }
  327. }
  328. .upload-cover {
  329. position: relative;
  330. &-text {
  331. position: absolute;
  332. bottom: 0;
  333. width: 100%;
  334. background-color: rgba($color: #000000, $alpha: 0.6);
  335. color: #FFFFFF;
  336. padding: 21rpx 0;
  337. }
  338. }
  339. </style>