apply.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <view :style="vuex_skin">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <u-navbar title-color="#000000" :is-back="true" title="我要报名"></u-navbar>
  5. <!-- #endif -->
  6. <view class="add-media" @click="handleUploadWork">
  7. <view class="flex-direction flex justify-center" style="align-items: center;" v-show="!showUrl">
  8. <u-icon name="plus-circle-fill" :color="vuex_theme.bgColor" size="90"></u-icon>
  9. <text style="margin-top: 26rpx; color: #010101; font-size: 24rpx; font-weight: bold; width: 70%; color: red;">{{tipsText}}</text>
  10. </view>
  11. <video v-if="activeType == 'VIDEO_TEXT' && showUrl" :src="showUrl"></video>
  12. <image v-if="activeType == 'IMAGE_TEXT' && showUrl" :src="showUrl" mode="aspectFill"></image>
  13. </view>
  14. <view class="fill-info">
  15. <text class="info-title" style="font-weight: bold; color: #010101; font-size: 34rpx;">填写信息</text>
  16. <view v-if="activeType == 'VIDEO_TEXT'" style="margin-bottom: 64rpx;">
  17. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> 作品封面</text>
  18. <view style="padding: 5rpx 0 20rpx; border-bottom: 1rpx solid #E3E3E3;">
  19. <upload-img ref="uploadImg" :count="1" col="4" @click="uploadCover"></upload-img>
  20. </view>
  21. </view>
  22. <view style="margin-bottom: 64rpx;">
  23. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> 标题</text>
  24. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  25. <u-input placeholder="请输入标题内容" v-model="applyInfo.title"></u-input>
  26. </view>
  27. </view>
  28. <view style="margin-bottom: 64rpx;">
  29. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> 参赛者</text>
  30. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  31. <u-input placeholder="请输入参赛者名称" v-model="applyInfo.player"></u-input>
  32. </view>
  33. </view>
  34. <view style="margin-bottom: 64rpx;" v-if="!!activeSetting && activeSetting.personShow === 1">
  35. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> {{activeSetting.personText}}</text>
  36. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  37. <u-input :placeholder="'请输入' + activeSetting.personText" v-model="applyInfo.guideTeacher"></u-input>
  38. </view>
  39. </view>
  40. <view style="margin-bottom: 64rpx;" v-if="!!activeSetting && activeSetting.orgShow === 1">
  41. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> {{activeSetting.org}}</text>
  42. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  43. <u-input :placeholder="'请输入' + activeSetting.org" v-model="applyInfo.guideSchool"></u-input>
  44. </view>
  45. </view>
  46. <view style="margin-bottom: 64rpx;">
  47. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> 详细介绍</text>
  48. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  49. <u-input placeholder="请输入详细介绍" v-model="applyInfo.content"></u-input>
  50. <!-- <u-input placeholder="请输入详细介绍" v-model="applyInfo.content" type="textarea" height="60" auto-height></u-input> -->
  51. </view>
  52. </view>
  53. <view style="margin-bottom: 64rpx;">
  54. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"><text style="color: #f00;">*</text> 联系方式</text>
  55. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  56. <u-input placeholder="请输入手机号码" v-model="applyInfo.phone"></u-input>
  57. </view>
  58. </view>
  59. <u-button shape="circle" :custom-style="customStyle" @click="submit">确定提交</u-button>
  60. </view>
  61. <compress ref="compress"></compress>
  62. <toast ref="toast"></toast>
  63. <uploadAlert ref="uploadAlert" :updateProgress="updateProgress" @cancelUpload="cancelUpload"></uploadAlert>
  64. </view>
  65. </template>
  66. <script>
  67. import compress from "@/components/compress.vue"
  68. import uploadImg from "@/components/uploadImg/uploadImg.vue"
  69. import uploadAlert from "@/components/alert/uploadAlert.vue"
  70. import config from "@/assets/http/config.js"
  71. let uploadTask
  72. export default {
  73. name: '',
  74. components: {
  75. compress,
  76. uploadImg,
  77. uploadAlert
  78. },
  79. data() {
  80. return {
  81. //压缩参数
  82. compressParams: {
  83. src: '',
  84. maxSize: 2048,
  85. fileType: 'jpg',
  86. quality: 1,
  87. minSize: 800 //最小压缩尺寸,图片尺寸小于该时值不压缩,非H5平台有效。若需要忽略该设置,可设置为一个极小的值,比如负数。
  88. },
  89. customStyle: {
  90. color: 'white',
  91. background: "#E72226",
  92. fontSize: '32rpx',
  93. width: '340rpx',
  94. margin: '25rpx auto 0'
  95. },
  96. //显示的url,有可能是图文,也有可能是视频
  97. showUrl: '',
  98. applyInfo: {},
  99. activeType: '', //活动类型: VIDEO_TEXT视频图文 IMAGE_TEXT图片文本
  100. updateProgress: '', //上传进度
  101. tipsText: '',
  102. activeSetting: '', //活动配置
  103. };
  104. },
  105. async onLoad(options) {
  106. if (this.$isEmpty(this.vuex_userId) ||
  107. this.$isEmpty(options.activeType) ||
  108. this.$isEmpty(options.activeId)) {
  109. uni.switchTab({
  110. url: "/pages/index/home"
  111. })
  112. return
  113. }
  114. let params = {
  115. activeId: this.vuex_active_setting.defaultActiveId,
  116. platformSettingEnum: 'ACTIVE_SETTING'
  117. }
  118. this.activeSetting = JSON.parse((await this.$api.platform.getPlatformValue(params)).data.data).guideRule[0];
  119. this.initData(options)
  120. },
  121. methods: {
  122. /**
  123. * 初始化数据
  124. */
  125. initData(options) {
  126. this.customStyle.background = this.vuex_theme.bgColor
  127. this.activeType = options.activeType;
  128. if(this.activeType === 'VIDEO_TEXT'){
  129. this.tipsText = '提示:视频拍摄后,微信转发保存,即可压缩上传,上传速度可以更快哦!';
  130. }else{
  131. this.tipsText = '上传图片作品';
  132. }
  133. // this.activeType = 'IMAGE_TEXT';
  134. this.applyInfo = {
  135. userId: this.vuex_userId,
  136. phone: this.vuex_phone,
  137. activeId: options.activeId,
  138. title: "",
  139. imgUrl: "",
  140. videoUrl: "",
  141. content: "",
  142. player: "",
  143. guideTeacher: "",
  144. guideSchool: ""
  145. }
  146. },
  147. /**
  148. * 上传封面
  149. */
  150. uploadCover(e) {
  151. this.applyInfo.imgUrl = e[0]
  152. },
  153. /**
  154. * 上传文件
  155. * 图文存进imgUrl
  156. */
  157. async uploadFile(params) {
  158. let res = await this.$api.uploadFile(params)
  159. if (this.activeType == 'VIDEO_TEXT') {
  160. this.applyInfo.videoUrl = res.data.data.link;
  161. } else {
  162. this.applyInfo.imgUrl = res.data.data.link
  163. }
  164. },
  165. /**
  166. * 上传作品
  167. */
  168. handleUploadWork() {
  169. if (this.activeType == 'VIDEO_TEXT') {
  170. //上传视频作品
  171. this.uploadVideoWork()
  172. } else {
  173. //上传图片作品
  174. this.uploadImageWork()
  175. }
  176. },
  177. /**
  178. * 上传图文作品
  179. */
  180. async uploadImageWork() {
  181. let res = await this.$mpi.chooseImage()
  182. this.compressParams.src = res[0]
  183. this.$dialog.showLoading('作品上传中..')
  184. let src= await this.$refs.compress.compress(this.compressParams)
  185. let resp = await this.$api.uploadFile(src)
  186. this.applyInfo.imgUrl = resp.data.data.link
  187. //显示的是图文链接
  188. this.showUrl = this.applyInfo.imgUrl
  189. uni.hideLoading()
  190. },
  191. /**
  192. * 上传视频作品
  193. */
  194. async uploadVideoWork() {
  195. let resp = await this.chooseVideo()
  196. // this.$dialog.showLoading('正在上传中..')
  197. this.$refs.uploadAlert.show = true;
  198. //上传视频链接
  199. let videoRes = await this.uploadVideo(resp.tempFilePath)
  200. this.applyInfo.videoUrl = videoRes.data.link;
  201. //上传视频封面链接
  202. // let coverRes = await this.$api.uploadFile(resp.thumbTempFilePath)
  203. // this.applyInfo.imgUrl = coverRes.data.data.link
  204. // this.$refs.uploadImg.imgList = [this.applyInfo.imgUrl]
  205. //显示的是视频链接
  206. this.showUrl = this.applyInfo.videoUrl
  207. uni.hideLoading()
  208. },
  209. /**
  210. * 取消视频作品
  211. */
  212. cancelUpload(){
  213. uploadTask.abort();
  214. },
  215. /**
  216. * 选择视频
  217. */
  218. chooseVideo() {
  219. var that = this;
  220. return new Promise((resolve, reject) => {
  221. uni.chooseVideo({
  222. count: 1,
  223. sourceType: ['album'],
  224. success: function(res) {
  225. let fileSize = (res.size/1024/1024).toFixed(2)
  226. console.log("视频大小", fileSize)
  227. if(fileSize > 50){
  228. that.$refs.toast.error('上传视频不能大于50M')
  229. return
  230. }
  231. resolve(res)
  232. },
  233. fail() {
  234. uni.hideLoading()
  235. }
  236. });
  237. })
  238. },
  239. /**
  240. * 上传视频
  241. */
  242. uploadVideo(tempFilePath) {
  243. let that = this;
  244. return new Promise((resolve, reject) => {
  245. uploadTask = uni.uploadFile({
  246. url: `${config.baseURL}/blade-resource/oss/endpoint/put-file`,
  247. filePath: tempFilePath,
  248. name: 'file',
  249. formData: { user: 'test' },
  250. header: { "Blade-Auth": uni.getStorageSync('token') },
  251. success(res) {
  252. resolve(JSON.parse(res.data))
  253. that.$refs.uploadAlert.show = false;
  254. that.updateProgress = '';
  255. },
  256. fail(err) {
  257. //用户取消上传
  258. if(err.errMsg === 'uploadFile:fail abort'){
  259. that.$refs.uploadAlert.show = false;
  260. that.updateProgress = '';
  261. that.$refs.toast.warn('取消上传')
  262. }
  263. }
  264. });
  265. uploadTask.onProgressUpdate(function(res) {
  266. that.updateProgress = res;
  267. console.log('上传进度' + res.progress);
  268. console.log('已经上传的数据长度' + res.totalBytesSent);
  269. console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
  270. });
  271. });
  272. },
  273. /**
  274. * 压缩视频
  275. */
  276. compressVideo() {
  277. uni.compressVideo({
  278. src: tempFilePath,
  279. quality: 'high', //'low':低,'medium':中,'high':高
  280. bitrate: 0,
  281. fps: 0,
  282. resolution: 0,
  283. success: function(csRes) {
  284. // 未进入
  285. console.log('压缩后大小')
  286. console.log(csRes.size)
  287. },
  288. fail: function(cfRes) {
  289. console.log(cfRes)
  290. uni.showToast({
  291. title: '视频压缩失败',
  292. icon: 'none'
  293. })
  294. }
  295. });
  296. },
  297. submit() {
  298. if (this.activeType == 'VIDEO_TEXT') {
  299. //视频
  300. if (this.$isEmpty(this.applyInfo.videoUrl)) {
  301. this.$refs.toast.warn('请上传视频作品')
  302. return
  303. }
  304. if (this.$isEmpty(this.applyInfo.imgUrl)) {
  305. this.$refs.toast.warn('请上传作品封面')
  306. return
  307. }
  308. } else {
  309. //图文
  310. if (this.$isEmpty(this.applyInfo.imgUrl)) {
  311. this.$refs.toast.warn('请上传图文作品')
  312. return
  313. }
  314. }
  315. if(!!this.activeSetting){
  316. if (this.$isEmpty(this.applyInfo.guideTeacher)) {
  317. this.$refs.toast.warn(`请输入${this.activeSetting.personText}`)
  318. return
  319. }
  320. if (this.$isEmpty(this.applyInfo.guideSchool)) {
  321. this.$refs.toast.warn(`请输入${this.activeSetting.org}`)
  322. return
  323. }
  324. }
  325. if (this.$isEmpty(this.applyInfo.title)) {
  326. this.$refs.toast.warn('请输入标题内容')
  327. return
  328. }
  329. if (this.$isEmpty(this.applyInfo.player)) {
  330. this.$refs.toast.warn('请输入参赛者名称')
  331. return
  332. }
  333. if (this.$isEmpty(this.applyInfo.content)) {
  334. this.$refs.toast.warn('请输入详细介绍')
  335. return
  336. }
  337. if (this.$isEmpty(this.applyInfo.phone)) {
  338. this.$refs.toast.warn('请输入手机号')
  339. return
  340. }
  341. this.$api.activity.submitForm(this.applyInfo).then(res => {
  342. if (res.data.success) {
  343. this.$dialog.showModalAndBack('添加成功', this.vuex_theme.bgColor)
  344. }
  345. })
  346. }
  347. }
  348. };
  349. </script>
  350. <style lang="scss" scoped>
  351. .add-media {
  352. width: 700rpx;
  353. height: 428rpx;
  354. border-radius: 14rpx;
  355. background: #FFFFFF;
  356. margin: 40rpx auto;
  357. display: flex;
  358. flex-direction: column;
  359. justify-content: center;
  360. align-items: center;
  361. }
  362. .fill-info {
  363. width: 700rpx;
  364. border-radius: 14rpx;
  365. background: #FFFFFF;
  366. margin: 0 auto;
  367. display: flex;
  368. flex-direction: column;
  369. padding: 40rpx 54rpx 50rpx;
  370. margin-bottom: 88rpx;
  371. .info-title {
  372. position: relative;
  373. margin-bottom: 60rpx;
  374. &:before {
  375. content: '';
  376. width: 8rpx;
  377. height: 32rpx;
  378. background: var(--bgColor);
  379. position: absolute;
  380. left: -18rpx;
  381. top: 50%;
  382. transform: translateY(-50%);
  383. }
  384. }
  385. }
  386. </style>