choice.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="content">
  3. <view class="nav">
  4. <view class="uni-page-head-btnBox">
  5. <view class="uni-page-head-btn" @click="goback"><i class="uni-btn-icon" ></i></view>
  6. </view>
  7. <view class="Navtitle">选择素材</view>
  8. <view class="uni-page-head-btnBox"></view>
  9. </view>
  10. <view class="zhidingyiBox">
  11. <view class="zhidingyi" @click="upimg">
  12. <view class="zdyLeft">
  13. <view class="zdyTitle">自定义图片</view>
  14. <view class="zdyms">建议尺寸:宽度750*390px</view>
  15. <view class="zdyms" style="padding-top: 24rpx;">请先上传自定义活动图片 后编辑活动内容</view>
  16. </view>
  17. <view class="zdyRight">
  18. <image src="../../static/img/bg_sucai@2x.png" mode="" class="zdyRightImg"></image>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="listBox">
  23. <view class="listLine" v-for="(item,i) in list" v-if="item.imgList.length>0">
  24. <view class="listTitle">{{item.Name}}</view>
  25. <view class="listSm">{{item.collectingComment}}</view>
  26. <scroll-view scroll-x="true" class="scroll-X" >
  27. <view class="listLineImgBox" >
  28. <view class="" v-for="(img,index) in item.imgList" @click="goAdd(img)">
  29. <image class="listLineImg" :src="img.Img" mode=""></image>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </view>
  35. <w-compress ref='wCompress' />
  36. </view>
  37. </template>
  38. <script>
  39. import WCompress from '@/components/w-compress/w-compress.vue'
  40. //https://ext.dcloud.net.cn/plugin?id=1718
  41. export default {
  42. components: {
  43. WCompress
  44. },
  45. data() {
  46. return {
  47. list:'',
  48. imgurl:'',
  49. type:'',
  50. }
  51. },
  52. onLoad(opt) {
  53. this.getSetTheGuestList();
  54. this.type=opt.type;
  55. //?token=1BAD122A96BA41E49200322381DC5D34&uid=DC0B84EA-A67B-4A4B-8EAE-F55A13CF8217
  56. },
  57. // onBackPress(e){
  58. // console.log(e)
  59. // console.log("返回")
  60. // return true;
  61. // },
  62. methods: {
  63. goback(){
  64. if(this.type==2){
  65. uni.navigateBack()
  66. }else{
  67. var standalone = window.navigator.standalone
  68. var userAgent = window.navigator.userAgent.toLowerCase()
  69. var safari = /safari/.test(userAgent)
  70. var ios = /iphone|ipod|ipad|mac/.test(userAgent)
  71. var android = /android/.test(userAgent)
  72. if (ios) {
  73. if ( true) {//!standalone&& !safari
  74. window.webkit.messageHandlers.goMyNav.postMessage(null)
  75. }
  76. } else if (android) {
  77. window.android.postMessage()
  78. }
  79. }
  80. },
  81. goAdd(item){
  82. uni.removeStorageSync('ckmusic');
  83. uni.navigateTo({
  84. url:'addActivity?img='+item.Img
  85. })
  86. },
  87. goAddzdy(img){
  88. uni.navigateTo({
  89. url:'addActivity?img='+img
  90. })
  91. },
  92. getSetTheGuestList(){
  93. uni.showLoading({
  94. title: '加载中'
  95. })
  96. this.$http('openH5SetTheGuest/getSetTheGuestList', {
  97. },'GET').then(res => {
  98. uni.hideLoading();
  99. this.list=res.data
  100. })
  101. },
  102. upimg(){
  103. var that = this;
  104. uni.chooseImage({
  105. sourceType: ['album','camera'],
  106. count:1,
  107. sizeType:['compressed'],
  108. success: (chooseImageRes) => {
  109. const tempFilePaths = chooseImageRes.tempFilePaths;
  110. console.log(tempFilePaths[0])
  111. //that.getImageInfo(tempFilePaths[0])
  112. that.file=tempFilePaths[0];
  113. that.$refs.wCompress.start(that.file, {
  114. pixels: 600000, // 最大分辨率,默认二百万
  115. quality: 0.8, // 压缩质量,默认0.8
  116. type: 'png', // 图片类型,默认jpg
  117. base64: true, // 是否返回base64,默认false,非H5有效
  118. }).then(resxx => {
  119. uni.uploadFile({
  120. url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例,非真实的接口地址
  121. filePath: resxx,
  122. name: 'file',
  123. formData: {
  124. 'user': 'test'
  125. },
  126. success: (uploadFileRes) => {
  127. console.log(JSON.parse(uploadFileRes.data).data );
  128. //that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
  129. that.imgurl=JSON.parse(uploadFileRes.data).data[0];
  130. that.goAddzdy(that.imgurl)
  131. }
  132. });
  133. }).catch(e => {
  134. })
  135. // }
  136. /* uni.uploadFile({
  137. url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例,非真实的接口地址
  138. filePath: tempFilePaths[0],
  139. name: 'file',
  140. formData: {
  141. 'user': 'test'
  142. },
  143. success: (uploadFileRes) => {
  144. console.log(JSON.parse(uploadFileRes.data).data );
  145. //that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
  146. that.imgurl=JSON.parse(uploadFileRes.data).data[0];
  147. that.goAddzdy(that.imgurl)
  148. }
  149. });
  150. */
  151. }
  152. });
  153. },
  154. getImageInfo(src){
  155. let _this = this
  156. uni.getImageInfo({
  157. src,
  158. success(res) {
  159. let canvasWidth = res.width //图片原始长宽
  160. let canvasHeight = res.height
  161. let ratio = canvasWidth / canvasHeight;
  162. if (canvasWidth > 500) {
  163. canvasWidth = 500;
  164. canvasHeight = Math.floor(canvasWidth / ratio);
  165. }
  166. let img = new Image()
  167. img.src = res.path
  168. let canvas = document.createElement('canvas');
  169. let ctx = canvas.getContext('2d')
  170. canvas.width = canvasWidth
  171. canvas.height = canvasHeight
  172. ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight)
  173. canvas.toBlob(function(fileSrc) {
  174. let imgSrc = window.URL.createObjectURL(fileSrc)
  175. _this.upimgfwq(imgSrc)
  176. })
  177. }
  178. })
  179. },
  180. upimgfwq(imgSrc){
  181. console.log(imgSrc)
  182. //let file = new File([imgSrc], '122.png')
  183. // var renameFile =new File([imgSrc], this.time(new Date()) + '.png' );
  184. // var formdata = new FormData();
  185. // formdata.append('file', renameFile);
  186. // console.log(formdata)
  187. var that=this;
  188. uni.uploadFile({
  189. url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例,非真实的接口地址
  190. filePath: imgSrc,
  191. name: 'file',
  192. formData: {
  193. 'user': 'test'
  194. },
  195. success: (uploadFileRes) => {
  196. console.log(JSON.parse(uploadFileRes.data).data );
  197. //that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
  198. that.imgurl=JSON.parse(uploadFileRes.data).data[0];
  199. that.goAddzdy(that.imgurl)
  200. }
  201. });
  202. },
  203. time(time) {
  204. let month = time.getMonth() + 1; // 月
  205. let date = time.getDate(); // 日
  206. let hh = time.getHours(); // 时
  207. let mm = time.getMinutes(); // 分
  208. let ss = time.getSeconds(); // 秒
  209. if (hh >=0 && hh<10){hh= '0' + hh;}
  210. if (mm >=0 && mm<10){mm= '0' + mm;}
  211. if (ss >=0 && ss<10){ss= '0' + ss;}
  212. if (month < 10){month= '0' + month;}
  213. if (date < 10){date= '0' + date;}
  214. return time.getFullYear().toString() + month.toString() + date.toString() + hh.toString() + mm.toString() + ss.toString();
  215. },
  216. }
  217. }
  218. </script>
  219. <style scoped>
  220. .nav{
  221. height: 44px;
  222. background: #ffffff;
  223. display: flex;
  224. justify-content: space-between;
  225. line-height: 44px;
  226. font-size: 16px;
  227. font-weight: 700;
  228. position: fixed;
  229. width: 750rpx;
  230. left: 0;
  231. top: 0;
  232. z-index: 11;
  233. }
  234. .uni-page-head-btnBox{
  235. width: 40px;
  236. padding-top: 5px;
  237. }
  238. .uni-btn-icon{
  239. color: #000000;
  240. font-size: 27px;
  241. }
  242. .content{
  243. min-height: 100vh;
  244. background:#F4F5F7 ;
  245. }
  246. .zhidingyiBox{
  247. padding: 20rpx 24rpx;
  248. margin-top: 44px;
  249. }
  250. .zhidingyi{
  251. background: #ffffff;
  252. border-radius: 10rpx;
  253. display: flex;
  254. justify-content: space-between;
  255. }
  256. .zdyRightImg{
  257. width: 217rpx;
  258. height: 210rpx;
  259. }
  260. .zdyLeft{
  261. padding-top: 50rpx;
  262. padding-left: 20rpx;
  263. width: 300rpx;
  264. } .zdyTitle{
  265. color: #333333;
  266. line-height: 42rpx;
  267. font-size: 30rpx;
  268. font-weight: 500;
  269. padding-bottom: 16rpx;
  270. }
  271. .zdyms{
  272. font-weight: 400;
  273. color: #999999;
  274. line-height: 33rpx;
  275. font-size: 24rpx;
  276. }
  277. .zdyRight{
  278. padding: 35rpx 30rpx;
  279. }
  280. .listBox{
  281. background: #ffffff;
  282. }
  283. .listLine{
  284. padding-left: 24rpx;
  285. padding-top: 30rpx;
  286. }
  287. .listLineImg{
  288. width: 630rpx;
  289. height: 252rpx;
  290. margin-right: 30rpx;
  291. border-radius: 10rpx;
  292. }
  293. .listLineImgBox{
  294. display: flex;
  295. }
  296. .listTitle{
  297. font-weight: 500;
  298. color: #333333;
  299. font-size: 30rpx;
  300. }
  301. .listSm{
  302. font-weight: 400;
  303. color: #999999;
  304. line-height: 33px;
  305. font-size: 24rpx;
  306. width: 702rpx;
  307. height: 33rpx;
  308. }
  309. </style>