add.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="">
  3. <view class="container">
  4. <view class="flex margin ">
  5. <view >
  6. <view v-if="!cover" @click="upload" class="add-icon flex justify-center align-center bg-gray">
  7. <text>添加视频</text>
  8. </view>
  9. <view v-if="cover" class="add-icon flex justify-center align-center bg-gray">
  10. <img mode="aspectFill" class="image-width" :src="static_url + cover" alt="">
  11. <text @click="delVideo" class="cuIcon-deletefill close-icon"></text>
  12. </view>
  13. </view>
  14. <view class="">
  15. <view class="margin-sm">
  16. <picker @change="bindPickerChange" range-key="name" :value="index" :range="cate_list">
  17. <view class="">视频类型:{{cate_list[index].name}}</view>
  18. </picker>
  19. </view>
  20. <textarea class="padding-left padding-right text-style flex-sub h240" v-model="title" placeholder="请添加作品描述" cols="30" rows="10"></textarea>
  21. </view>
  22. </view>
  23. <button class="cu-btn flex-sub bg-red margin block shadow shadow-blur shadow-lg" @click="publish">
  24. <text class="cuIcon-upload margin-right-sm"></text>
  25. <text class="text-df">发布视频</text>
  26. </button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import uniIcons from '@/components/uni-icons/uni-icons.vue'
  32. export default {
  33. data() {
  34. return {
  35. video: '', //视频
  36. cover: '', //封面
  37. title: '', //标题
  38. static_url: '', //静态资源地址
  39. loading: false, //上传中
  40. cate_list:[],
  41. index:0
  42. }
  43. },
  44. components: {
  45. uniIcons
  46. },
  47. mounted() {
  48. this.static_url = getApp().globalData.static_url;
  49. this.getCate();
  50. },
  51. methods: {
  52. bindPickerChange(e){
  53. console.log('picker发送选择改变,携带值为', e.detail.value)
  54. this.index = e.detail.value
  55. },
  56. // 获取分类
  57. getCate(){
  58. this.$httpSend({
  59. path: '/im/video.Share/category',
  60. success: (data) => {
  61. console.log("data", data);
  62. this.cate_list = data;
  63. }
  64. })
  65. },
  66. upload() {
  67. uni.chooseVideo({
  68. success: (res) => {
  69. console.log("res", res);
  70. this.$httpSendFile({
  71. local_url: res.tempFilePath,
  72. type: 6,
  73. success: (data) => {
  74. console.log("data", data);
  75. this.cover = data.save_gif_path;
  76. this.video = data.save_name;
  77. },
  78. });
  79. }
  80. })
  81. },
  82. publish() {
  83. if (!this.video || !this.cover) {
  84. uni.showToast({
  85. icon: 'none',
  86. title: '请添加视频'
  87. })
  88. return
  89. }
  90. if (!this.title) {
  91. uni.showToast({
  92. icon: 'none',
  93. title: '请添加作品描述'
  94. })
  95. return
  96. }
  97. if (!this.loading) {
  98. this.submit();
  99. } else {
  100. uni.showToast({
  101. icon: 'none',
  102. title: '上传中'
  103. })
  104. }
  105. },
  106. submit() {
  107. this.loading = true;
  108. this.$httpSend({
  109. path: '/im/video.Share/release',
  110. data: {
  111. title: this.title,
  112. gif: this.cover,
  113. video: this.video,
  114. category_id:this.cate_list[this.index].id,
  115. },
  116. success: (data) => {
  117. console.log("data", data);
  118. this.loading = false;
  119. uni.showToast({
  120. icon: 'none',
  121. title: '发布成功',
  122. })
  123. }
  124. })
  125. },
  126. delVideo() {
  127. this.video = '';
  128. this.cover = '';
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped>
  134. @import '@/static/css/colorui/main.css';
  135. @import '@/static/css/colorui/icon.css';
  136. page {
  137. background: #fff;
  138. font-size: 40rpx;
  139. }
  140. .text-style {
  141. font-style: italic;
  142. height: 80rpx;
  143. }
  144. .h240{
  145. height: 240rpx;
  146. }
  147. .add-icon {
  148. width: 240rpx;
  149. height: 240rpx;
  150. background: #eeeeee;
  151. border-radius: 10px;
  152. position: relative;
  153. overflow: hidden;
  154. }
  155. .image-width {
  156. width: 100%;
  157. height: auto;
  158. }
  159. .close-icon {
  160. position: absolute;
  161. right: 10rpx;
  162. top: 0;
  163. font-size: 50rpx;
  164. z-index: 1;
  165. color: #fff;
  166. }
  167. .cu-btn {
  168. height: 80rpx;
  169. }
  170. </style>