choice.vue 9.7 KB

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