testimage.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="burst-wrap">
  3. <view class="burst-wrap-bg">
  4. <view>
  5. <!-- 信息提交 -->
  6. <view class="burst-info">
  7. <view class="uni-uploader-body">
  8. <view class="uni-uploader__files">
  9. <!-- 图片 -->
  10. <block v-for="(image,index) in imageList" :key="index">
  11. <view class="uni-uploader__file">
  12. <view class="icon iconfont icon-cuo" @tap="delect(index)"></view>
  13. <image class="uni-uploader__img" :src="image" :data-src="image" @tap="previewImage"></image>
  14. </view>
  15. </block>
  16. <!-- 视频 -->
  17. <view class="uni-uploader__file" v-if="src">
  18. <view class="uploader_video">
  19. <view class="icon iconfont icon-cuo" @tap="delectVideo"></view>
  20. <video :src="src" class="video"></video>
  21. </view>
  22. </view>
  23. <view class="uni-uploader__input-box" v-if="VideoOfImagesShow">
  24. <view class="uni-uploader__input" @tap="chooseVideoImage">上传图片</view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. var sourceType = [
  35. ['camera'],
  36. ['album'],
  37. ['camera', 'album']
  38. ]
  39. export default {
  40. data() {
  41. return {
  42. imageList:[],//图片
  43. src:"",//视频存放
  44. sourceTypeIndex: 2,
  45. checkedValue:true,
  46. checkedIndex:0,
  47. sourceType: ['拍摄', '相册', '拍摄或相册'],
  48. cameraList: [{
  49. value: 'back',
  50. name: '后置摄像头',
  51. checked: 'true'
  52. },
  53. {
  54. value: 'front',
  55. name: '前置摄像头'
  56. },
  57. ],
  58. cameraIndex: 0,
  59. VideoOfImagesShow:true,
  60. }
  61. },
  62. onUnload() {
  63. this.src = '',
  64. this.sourceTypeIndex = 2,
  65. this.sourceType = ['拍摄', '相册', '拍摄或相册'];
  66. },
  67. methods: {
  68. chooseVideoImage(){
  69. uni.showActionSheet({
  70. title:"选择上传类型",
  71. itemList: ['图片','视频'],
  72. success: (res) => {
  73. console.log(res)
  74. if(res.tapIndex == 0){
  75. this.chooseImages()
  76. } else {
  77. this.chooseVideo()
  78. }
  79. }
  80. })
  81. },
  82. chooseImages(){
  83. // 上传图片
  84. uni.chooseImage({
  85. count: 4, //默认9
  86. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  87. sourceType: ['album','camera'], //从相册选择
  88. success:(res)=> {
  89. let igmFile = res.tempFilePaths;
  90. uni.uploadFile({
  91. url:this.config.fileUrl,
  92. method:"POST",
  93. header:{
  94. 'Authorization':'bearer '+ uni.getStorageSync("apiToken"),
  95. 'Content-Type':'multipart/form-data'
  96. },
  97. filePath:igmFile[0],
  98. name:'file',
  99. success: (res) =>{
  100. // let imgUrls = JSON.parse(res.data); //微信和头条支持
  101. let imgUrls = res.data //百度支持
  102. this.imagesUrlPath = this.imagesUrlPath.concat(imgUrls.result.filePath);
  103. this.imageList = this.imageList.concat(imgUrls.result.filePath); //微信
  104. if(this.imageList.length>=4) {
  105. this.VideoOfImagesShow = false;
  106. } else {
  107. this.VideoOfImagesShow = true;
  108. }
  109. }
  110. })
  111. // this.imageList = this.imageList.concat(res.tempFilePaths) //头条
  112. },
  113. });
  114. },
  115. chooseVideo(){
  116. // 上传视频
  117. uni.chooseVideo({
  118. maxDuration:60,
  119. count: 1,
  120. camera: this.cameraList[this.cameraIndex].value,
  121. sourceType: ['album'],
  122. success: (responent) => {
  123. let videoFile = responent.tempFilePath;
  124. uni.uploadFile({
  125. url:this.config.fileUrl,
  126. method:"POST",
  127. header:{
  128. 'Authorization':'bearer '+ uni.getStorageSync("apiToken")
  129. },
  130. filePath:videoFile,
  131. name:'file',
  132. success: (res) => {
  133. // let videoUrls = JSON.parse(res.data) //微信和头条支持
  134. let videoUrls = res.data //百度支持
  135. this.imagesUrlPath = this.imagesUrlPath.concat(videoUrls.result.filePath);
  136. this.src = videoUrls.result.filePath; //微信
  137. if(this.src) {
  138. this.itemList = ['图片']
  139. } else {
  140. this.itemList = ['图片','视频']
  141. }
  142. }
  143. })
  144. // this.src = responent.tempFilePath; //头条
  145. }
  146. })
  147. },
  148. previewImage: function(e) {
  149. //预览图片
  150. var current = e.target.dataset.src
  151. uni.previewImage({
  152. current: current,
  153. urls: this.imageList
  154. })
  155. },
  156. delect(index){
  157. uni.showModal({
  158. title: "提示",
  159. content: "是否要删除该图片",
  160. success: (res) => {
  161. if (res.confirm) {
  162. this.imageList.splice(index, 1)
  163. }
  164. }
  165. })
  166. },
  167. delectVideo(){
  168. uni.showModal({
  169. title:"提示",
  170. content:"是否要删除此视频",
  171. success:(res) =>{
  172. if(res.confirm){
  173. this.src = ''
  174. }
  175. }
  176. })
  177. }
  178. }
  179. }
  180. </script>
  181. <style>
  182. .burst-wrap{
  183. width: 100%;
  184. height: 100%;
  185. }
  186. /* .burst-wrap .burst-wrap-bg{
  187. position: relative;
  188. width: 100%;
  189. height: 320upx;
  190. background:linear-gradient(90deg,rgba(251,91,80,1) 0%,rgba(240,45,51,1) 100%);
  191. border-bottom-right-radius: 80upx;
  192. border-bottom-left-radius: 80upx;
  193. } */
  194. .burst-wrap .burst-wrap-bg>view{
  195. width: 90%;
  196. height: 100%;
  197. margin: 0 auto;
  198. position: absolute;
  199. top: 65upx;
  200. left: 0;
  201. right: 0;
  202. }
  203. .form-item{
  204. width: 100%;
  205. }
  206. .form-item textarea{
  207. display: block;
  208. height: 220upx;
  209. width: 100%;
  210. color: #AAAAAA;
  211. font-size: 28upx;
  212. }
  213. .uni-uploader__file,.uploader_video{
  214. position: relative;
  215. z-index: 1;
  216. width: 200upx;
  217. height: 200upx;
  218. }
  219. .uni-uploader__img {
  220. width: 200upx;
  221. height: 200upx;
  222. }
  223. .icon-cuo {
  224. position: absolute;
  225. right: 0;
  226. top: 5upx;
  227. background: linear-gradient(90deg,rgba(251,91,80,1) 0%,rgba(240,45,51,1) 100%);
  228. color: #FFFFFF;
  229. z-index: 999;
  230. border-top-right-radius: 20upx;
  231. border-bottom-left-radius: 20upx;
  232. }
  233. .video{
  234. width: 100%;
  235. height: 100%;
  236. }
  237. .login-input-box{
  238. position: relative;
  239. border-bottom: 1upx solid #EEEEEE;
  240. }
  241. .login-input-box .forget,.login-input-box .phone{
  242. position: absolute;
  243. top: 0;
  244. height: 100%;
  245. z-index: 100;
  246. }
  247. .login-input-box .phone{
  248. width: 100upx;
  249. left: 0;
  250. color: #666666;
  251. font-weight: bold;
  252. }
  253. .login-input-box .phone-input{
  254. padding-left: 100upx;
  255. }
  256. .address-wrap,.open-info{
  257. margin-top: 20upx;
  258. }
  259. .open-info>view:last-child{
  260. font-size: 28upx;
  261. color: #999999;
  262. }
  263. .address-wrap .address {
  264. background: #F2F2F2;
  265. border-radius: 40upx;
  266. padding: 0 20upx;
  267. }
  268. .user-set-btn{
  269. margin: 40upx;
  270. background: linear-gradient(90deg,rgba(251,91,80,1) 0%,rgba(240,45,51,1) 100%);
  271. color: #FFFFFF;
  272. text-align: center;
  273. height: 88upx;
  274. line-height: 88upx;
  275. }
  276. </style>