apply.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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="guide === 1">
  35. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"> 指导老师</text>
  36. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  37. <u-input placeholder="请输入指导老师" v-model="applyInfo.guideTeacher"></u-input>
  38. </view>
  39. </view>
  40. <view style="margin-bottom: 64rpx;" v-if="guide === 1">
  41. <text style="color: #010101; font-size: 28rpx; font-weight: bold;"> 指导机构</text>
  42. <view style="padding: 32rpx 0 0; border-bottom: 1rpx solid #E3E3E3;">
  43. <u-input placeholder="请输入指导机构" 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. guide: null, //是否需要指导老师和指导机构
  103. };
  104. },
  105. 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. this.initData(options)
  115. },
  116. methods: {
  117. /**
  118. * 初始化数据
  119. */
  120. initData(options) {
  121. this.guide = options.guide;
  122. this.customStyle.background = this.vuex_theme.bgColor
  123. this.activeType = options.activeType;
  124. if(this.activeType === 'VIDEO_TEXT'){
  125. this.tipsText = '提示:视频拍摄后,微信转发保存,即可压缩上传,上传速度可以更快哦!';
  126. }else{
  127. this.tipsText = '上传图片作品';
  128. }
  129. // this.activeType = 'IMAGE_TEXT';
  130. this.applyInfo = {
  131. userId: this.vuex_userId,
  132. phone: this.vuex_phone,
  133. activeId: options.activeId,
  134. title: "",
  135. imgUrl: "",
  136. videoUrl: "",
  137. content: "",
  138. player: "",
  139. guideTeacher: "",
  140. guideSchool: ""
  141. }
  142. },
  143. /**
  144. * 上传封面
  145. */
  146. uploadCover(e) {
  147. this.applyInfo.imgUrl = e[0]
  148. },
  149. /**
  150. * 上传文件
  151. * 图文存进imgUrl
  152. */
  153. async uploadFile(params) {
  154. let res = await this.$api.uploadFile(params)
  155. if (this.activeType == 'VIDEO_TEXT') {
  156. this.applyInfo.videoUrl = res.data.data.link;
  157. } else {
  158. this.applyInfo.imgUrl = res.data.data.link
  159. }
  160. },
  161. /**
  162. * 上传作品
  163. */
  164. handleUploadWork() {
  165. if (this.activeType == 'VIDEO_TEXT') {
  166. //上传视频作品
  167. this.uploadVideoWork()
  168. } else {
  169. //上传图片作品
  170. this.uploadImageWork()
  171. }
  172. },
  173. /**
  174. * 上传图文作品
  175. */
  176. async uploadImageWork() {
  177. let res = await this.$mpi.chooseImage()
  178. this.compressParams.src = res[0]
  179. this.$dialog.showLoading('作品上传中..')
  180. let src= await this.$refs.compress.compress(this.compressParams)
  181. let resp = await this.$api.uploadFile(src)
  182. this.applyInfo.imgUrl = resp.data.data.link
  183. //显示的是图文链接
  184. this.showUrl = this.applyInfo.imgUrl
  185. uni.hideLoading()
  186. },
  187. /**
  188. * 上传视频作品
  189. */
  190. async uploadVideoWork() {
  191. let resp = await this.chooseVideo()
  192. // this.$dialog.showLoading('正在上传中..')
  193. this.$refs.uploadAlert.show = true;
  194. //上传视频链接
  195. let videoRes = await this.uploadVideo(resp.tempFilePath)
  196. this.applyInfo.videoUrl = videoRes.data.link;
  197. //上传视频封面链接
  198. // let coverRes = await this.$api.uploadFile(resp.thumbTempFilePath)
  199. // this.applyInfo.imgUrl = coverRes.data.data.link
  200. // this.$refs.uploadImg.imgList = [this.applyInfo.imgUrl]
  201. //显示的是视频链接
  202. this.showUrl = this.applyInfo.videoUrl
  203. uni.hideLoading()
  204. },
  205. /**
  206. * 取消视频作品
  207. */
  208. cancelUpload(){
  209. uploadTask.abort();
  210. },
  211. /**
  212. * 选择视频
  213. */
  214. chooseVideo() {
  215. var that = this;
  216. return new Promise((resolve, reject) => {
  217. uni.chooseVideo({
  218. count: 1,
  219. sourceType: ['album'],
  220. success: function(res) {
  221. let fileSize = (res.size/1024/1024).toFixed(2)
  222. console.log("视频大小", fileSize)
  223. if(fileSize > 50){
  224. that.$refs.toast.error('上传视频不能大于50M')
  225. return
  226. }
  227. resolve(res)
  228. },
  229. fail() {
  230. uni.hideLoading()
  231. }
  232. });
  233. })
  234. },
  235. /**
  236. * 上传视频
  237. */
  238. uploadVideo(tempFilePath) {
  239. let that = this;
  240. return new Promise((resolve, reject) => {
  241. uploadTask = uni.uploadFile({
  242. url: `${config.baseURL}/blade-resource/oss/endpoint/put-file`,
  243. filePath: tempFilePath,
  244. name: 'file',
  245. formData: { user: 'test' },
  246. header: { "Blade-Auth": uni.getStorageSync('token') },
  247. success(res) {
  248. resolve(JSON.parse(res.data))
  249. that.$refs.uploadAlert.show = false;
  250. that.updateProgress = '';
  251. },
  252. fail(err) {
  253. //用户取消上传
  254. if(err.errMsg === 'uploadFile:fail abort'){
  255. that.$refs.uploadAlert.show = false;
  256. that.updateProgress = '';
  257. that.$refs.toast.warn('取消上传')
  258. }
  259. }
  260. });
  261. uploadTask.onProgressUpdate(function(res) {
  262. that.updateProgress = res;
  263. console.log('上传进度' + res.progress);
  264. console.log('已经上传的数据长度' + res.totalBytesSent);
  265. console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
  266. });
  267. });
  268. },
  269. /**
  270. * 压缩视频
  271. */
  272. compressVideo() {
  273. uni.compressVideo({
  274. src: tempFilePath,
  275. quality: 'high', //'low':低,'medium':中,'high':高
  276. bitrate: 0,
  277. fps: 0,
  278. resolution: 0,
  279. success: function(csRes) {
  280. // 未进入
  281. console.log('压缩后大小')
  282. console.log(csRes.size)
  283. },
  284. fail: function(cfRes) {
  285. console.log(cfRes)
  286. uni.showToast({
  287. title: '视频压缩失败',
  288. icon: 'none'
  289. })
  290. }
  291. });
  292. },
  293. submit() {
  294. if (this.activeType == 'VIDEO_TEXT') {
  295. //视频
  296. if (this.$isEmpty(this.applyInfo.videoUrl)) {
  297. this.$refs.toast.warn('请上传视频作品')
  298. return
  299. }
  300. if (this.$isEmpty(this.applyInfo.imgUrl)) {
  301. this.$refs.toast.warn('请上传作品封面')
  302. return
  303. }
  304. } else {
  305. //图文
  306. if (this.$isEmpty(this.applyInfo.imgUrl)) {
  307. this.$refs.toast.warn('请上传图文作品')
  308. return
  309. }
  310. }
  311. if (this.$isEmpty(this.applyInfo.title)) {
  312. this.$refs.toast.warn('请输入标题内容')
  313. return
  314. }
  315. if (this.$isEmpty(this.applyInfo.player)) {
  316. this.$refs.toast.warn('请输入参赛者名称')
  317. return
  318. }
  319. if (this.$isEmpty(this.applyInfo.content)) {
  320. this.$refs.toast.warn('请输入详细介绍')
  321. return
  322. }
  323. if (this.$isEmpty(this.applyInfo.phone)) {
  324. this.$refs.toast.warn('请输入手机号')
  325. return
  326. }
  327. this.$api.activity.submitForm(this.applyInfo).then(res => {
  328. if (res.data.success) {
  329. this.$dialog.showModalAndBack('添加成功', this.vuex_theme.bgColor)
  330. }
  331. })
  332. }
  333. }
  334. };
  335. </script>
  336. <style lang="scss" scoped>
  337. .add-media {
  338. width: 700rpx;
  339. height: 428rpx;
  340. border-radius: 14rpx;
  341. background: #FFFFFF;
  342. margin: 40rpx auto;
  343. display: flex;
  344. flex-direction: column;
  345. justify-content: center;
  346. align-items: center;
  347. }
  348. .fill-info {
  349. width: 700rpx;
  350. border-radius: 14rpx;
  351. background: #FFFFFF;
  352. margin: 0 auto;
  353. display: flex;
  354. flex-direction: column;
  355. padding: 40rpx 54rpx 50rpx;
  356. margin-bottom: 88rpx;
  357. .info-title {
  358. position: relative;
  359. margin-bottom: 60rpx;
  360. &:before {
  361. content: '';
  362. width: 8rpx;
  363. height: 32rpx;
  364. background: var(--bgColor);
  365. position: absolute;
  366. left: -18rpx;
  367. top: 50%;
  368. transform: translateY(-50%);
  369. }
  370. }
  371. }
  372. </style>