faceVideo.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="container">
  3. <view id="topnav" class="topnav flex-between" :style="{'height':`${topbarOffsetHeight-statusBarHeight}px`,'padding-top':`${statusBarHeight}px`}">
  4. <view class="nav-item flex-center" @click="back">
  5. <image :src="`${assetsUrl}back.png`" mode="widthFix" class="nav-img"></image>
  6. </view>
  7. <view class="nav-text font32 fw600">
  8. {{topbarTitle}}
  9. </view>
  10. <view class="nav-item"></view>
  11. </view>
  12. <view class="upload-box flex-center" @click="chooseMedia">
  13. <image :src="`${assetsUrl}mine-camera.png`" mode="widthFix" class="upload-img"></image>
  14. <view class="upload-text font28 fw400">选择视频</view>
  15. </view>
  16. <view class="tip font22 fw400">
  17. 点击添加你的封面视频
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {getPolicy,computeSignature,getKey} from '@/util/oss.js';
  23. import {encode} from '@/util/base64.js'
  24. export default {
  25. data() {
  26. return {
  27. topbarIcon:'back',
  28. topbarTitle:'编辑封面视频',
  29. assetsUrl:this.$util.assetsUrl,
  30. topNavHeight:0,
  31. options:{
  32. completeUser:null,
  33. pageHomeUserId:null,
  34. personalPageHomeVideoOperateEnum:'UPLOAD',
  35. personalPageHomeVideoUrl: "",
  36. sizeMB: 0,
  37. vdoTime: 0,
  38. width: 0,
  39. height:0
  40. }
  41. };
  42. },
  43. mounted() {
  44. this.computedScollviewHeight();
  45. },
  46. computed: {
  47. statusBarHeight() {
  48. return this.$store.state.statusBarHeight;
  49. },
  50. topbarOffsetHeight() {
  51. return this.$store.state.topbarOffsetHeight;
  52. },
  53. userInfo(){
  54. return this.$store.state.userInfo||JSON.parse(uni.getStorageSync('userInfo'))
  55. }
  56. },
  57. methods:{
  58. back(){
  59. uni.navigateBack({
  60. delta:1
  61. })
  62. },
  63. /**
  64. * 计算scroll高度
  65. */
  66. computedScollviewHeight() {
  67. let query = uni.createSelectorQuery().in(this);
  68. let heightLeaf =0;
  69. query.select('#topnav').boundingClientRect(data => {
  70. this.topNavHeight=data.height;
  71. heightLeaf += data.height;
  72. }).exec(() => {
  73. let sysInfo = uni.getSystemInfoSync();
  74. this.scrollHeight = sysInfo.windowHeight - heightLeaf;
  75. });
  76. },
  77. chooseMedia(){
  78. const that=this;
  79. uni.chooseMedia({
  80. count: 1,
  81. mediaType: ['video'],
  82. sourceType: ['album', 'camera'],
  83. maxDuration: 30,
  84. camera: 'back',
  85. success:(res)=>{
  86. console.log(res.tempFiles[0]);
  87. uni.showLoading({
  88. title:'正在上传',
  89. mask:true
  90. })
  91. const policyText=getPolicy();
  92. const policy=encode(JSON.stringify(policyText));
  93. const key=getKey(0,res.tempFiles[0].tempFilePath.split('.')[1]);
  94. that.$api.public.aliossToken({}).then(resuslt=>{
  95. let formData={
  96. key:key,
  97. policy:policy,
  98. OSSAccessKeyId:resuslt.data.accessKeyId,
  99. signature:computeSignature(resuslt.data.accessKeySecret,policy),
  100. 'x-oss-security-token':resuslt.data.securityToken,
  101. success_action_status:'200'
  102. }
  103. uni.uploadFile({
  104. url: 'https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com',
  105. filePath:res.tempFiles[0].tempFilePath,
  106. name: 'file',
  107. header:{
  108. "Content-Type": "multipart/form-data"
  109. },
  110. formData: formData,
  111. success: (data) => {
  112. if (data.statusCode === 200) {
  113. let videoUrl=`${that.$store.state.videoCdn}/${key}`;
  114. let user=JSON.parse(uni.getStorageSync('user'));
  115. that.options.height=res.tempFiles[0].height;
  116. that.options.width=res.tempFiles[0].width;
  117. that.options.completeUser=user;
  118. that.options.pageHomeUserId=user.id;
  119. that.options.sizeMB=res.tempFiles[0].size/1024/1024;
  120. that.options.personalPageHomeVideoUrl=videoUrl;
  121. that.options.vdoTime=res.tempFiles[0].duration;
  122. that.$api.public.videoProcess(that.options).then(res=>{
  123. uni.hideLoading()
  124. if(res.status==='Succ'){
  125. uni.showToast({
  126. icon:'success',
  127. title:'上传成功'
  128. });
  129. setTimeout(()=>{
  130. uni.navigateBack({
  131. delta:1
  132. })
  133. },1500)
  134. }
  135. else{
  136. uni.showToast({
  137. icon:'none',
  138. title:'上传失败,请重试!'
  139. });
  140. }
  141. })
  142. }
  143. },
  144. fail: err => {
  145. console.log(err);
  146. }
  147. })
  148. })
  149. }
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .container{
  157. width: 100vw;
  158. height: 100vh;
  159. background-color: $bgcolor1;
  160. overflow: hidden;
  161. position: relative;
  162. .topnav {
  163. padding: 0 10rpx;
  164. position: fixed;
  165. top: 0;
  166. left: 0;
  167. width: 100vw;
  168. z-index: 100;
  169. background-color: $bgcolor1;
  170. .nav-item{
  171. width: 40rpx;
  172. height: 40rpx;
  173. margin-left: 16rpx;
  174. .nav-img{
  175. width: 40rpx;
  176. height: 40rpx;
  177. }
  178. }
  179. .nav-text{
  180. flex: 1;
  181. color: $fontcolor5;
  182. height: 40rpx;
  183. text-align: center;
  184. }
  185. }
  186. .upload-box{
  187. flex-direction: column;
  188. width: 360rpx;
  189. height: 360rpx;
  190. background: #1F1A30;
  191. border-radius: 16rpx;
  192. position: absolute;
  193. left: 0;
  194. right: 0;
  195. top: 0;
  196. bottom: 0;
  197. margin: auto;
  198. .upload-img{
  199. width: 80rpx;
  200. height: 80rpx;
  201. }
  202. .upload-text{
  203. color: #ffffff;
  204. margin-top: 8rpx;
  205. }
  206. }
  207. .tip{
  208. color: #7D7DA4;
  209. margin-top: 40rpxs;
  210. }
  211. }
  212. </style>