poster.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="">
  3. <!-- <view class="content">
  4. <view class="poster">
  5. <image src="https:\/\/t38.9026.com\/uploads\/golf\/images\/2022-05-31\/20220531739250.png" mode="aspectFill"></image>
  6. <view class="code">
  7. <image src="../../static/travelD/code.png" mode="aspectFill"></image>
  8. </view>
  9. </view>
  10. <view class="title">
  11. <view class="kangyang">
  12. <text>
  13. {{goodsInfo.name}}
  14. </text>
  15. </view>
  16. <view class="">
  17. ¥{{goodsInfo.min_price}}/人起
  18. </view>
  19. </view>
  20. <view class="" style="font-size: 22rpx;color: #666666;">
  21. {{created_at?created_at:''}}
  22. </view>
  23. </view> -->
  24. <!-- <view class="content">
  25. <image :src="" mode="aspectFill"></image>
  26. </view> -->
  27. <view class="imgbox">
  28. <!-- {{imgurl}} -->
  29. <image :src="imgurl" mode="aspectFit"></image>
  30. </view>
  31. <view class="flex">
  32. <view class="weix">
  33. <button type="default" open-type="share" style="background-color: transparent;border-style:none;border:0;padding: 0;line-height: 30rpx;">
  34. <image src="../../static/travelD/wxin.png" mode="widthFix"></image>
  35. <view class="text">
  36. 分享
  37. </view>
  38. </button>
  39. </view>
  40. <view class="xiangc" @click="savePoster">
  41. <image src="../../static/travelD/album.png" mode="widthFix"></image>
  42. <view class="text">
  43. 手机相册
  44. </view>
  45. </view>
  46. </view>
  47. <view class="paddingsafe"></view>
  48. </view>
  49. </template>
  50. <script>
  51. let that
  52. export default {
  53. data(){
  54. return{
  55. goodsInfo:null,
  56. good_id:'',
  57. imgurl:''
  58. }
  59. },
  60. // #ifdef MP
  61. onShareAppMessage(options){
  62. var that = this;
  63. var shareObj = {
  64. title: this.goodsInfo.name,
  65. path: "/pages/travel/travelDetails?id="+that.goodsInfo.id,
  66. imageUrl: '',
  67. };
  68. if( options.from == 'button' ){
  69. shareObj.path = "/pages/travel/travelDetails?id="+that.goodsInfo.id
  70. }
  71. return shareObj;
  72. },
  73. // #endif
  74. onLoad(o) {
  75. that=this
  76. if(o.goodsInfo){
  77. let goodsInfo = decodeURIComponent(o.goodsInfo)
  78. this.goodsInfo = JSON.parse(goodsInfo)
  79. }
  80. this.init()
  81. },
  82. computed:{
  83. // created_at(){
  84. // let created_at=''
  85. // if(this.goodsInfo.created_at){
  86. // created_at=this.goodsInfo.created_at.slice(0,10)
  87. // }
  88. // return created_at
  89. // }
  90. },
  91. methods:{
  92. init(){
  93. uni.showLoading()
  94. uni.$u.http.post('/api/share/good', {
  95. good_id: this.goodsInfo.id
  96. }, {
  97. custom: {
  98. auth: true
  99. }
  100. }).then((res) => {
  101. console.log(res)
  102. that.imgurl=res.url
  103. uni.hideLoading()
  104. }).catch((err) => {
  105. uni.hideLoading()
  106. console.log(err)
  107. })
  108. },
  109. savePoster() {
  110. uni.showLoading({
  111. title: '正在保存图片...'
  112. });
  113. //获取用户的当前设置。获取相册权限
  114. uni.getSetting({
  115. success: (res) => {
  116. //如果没有相册权限
  117. console.log(22222)
  118. if (!res.authSetting["scope.writePhotosAlbum"]) {
  119. //向用户发起授权请求
  120. uni.authorize({
  121. scope: "scope.writePhotosAlbum",
  122. success: () => {
  123. //授权成功保存图片到系统相册
  124. uni.downloadFile({
  125. url: that.imgurl,
  126. success: (res) => {
  127. uni.hideLoading();
  128. console.log(res)
  129. if (res.statusCode === 200) {
  130. uni.saveImageToPhotosAlbum({
  131. filePath: res.tempFilePath,
  132. success: function() {
  133. uni.showToast({
  134. title: "保存成功",
  135. icon: "none"
  136. });
  137. },
  138. fail: function() {
  139. uni.showToast({
  140. title: "保存失败",
  141. icon: "none"
  142. });
  143. }
  144. });
  145. }
  146. }
  147. })
  148. },
  149. //授权失败
  150. fail: () => {
  151. uni.hideLoading();
  152. uni.showModal({
  153. title: "您已拒绝获取相册权限",
  154. content: "是否进入权限管理,调整授权?",
  155. success: (res) => {
  156. if (res.confirm) {
  157. //调起客户端小程序设置界面,返回用户设置的操作结果。(重新让用户授权)
  158. uni.openSetting({
  159. success: (res) => {
  160. console.log(res.authSetting);
  161. },
  162. });
  163. } else if (res.cancel) {
  164. return uni.showToast({
  165. title: "已取消!",
  166. });
  167. }
  168. },
  169. });
  170. },
  171. });
  172. } else {
  173. console.log(22222)
  174. //如果已有相册权限,直接保存图片到系统相册
  175. uni.downloadFile({
  176. url:that.imgurl,
  177. success: (res) => {
  178. console.log(res,996)
  179. if (res.statusCode === 200) {
  180. uni.saveImageToPhotosAlbum({
  181. filePath: res.tempFilePath,
  182. success: function() {
  183. uni.hideLoading()
  184. uni.showToast({
  185. title: "保存成功",
  186. icon: "none"
  187. });
  188. },
  189. fail: function() {
  190. uni.hideLoading()
  191. uni.showToast({
  192. title: "保存失败",
  193. icon: "none"
  194. });
  195. }
  196. });
  197. }
  198. }
  199. })
  200. }
  201. },
  202. fail: (res) => {},
  203. });
  204. },
  205. }
  206. }
  207. </script>
  208. <style lang="less">
  209. page{
  210. background-color: #F4F4F4;
  211. }
  212. .imgbox{
  213. margin: 20rpx auto;
  214. width: 624rpx;
  215. height: 960rpx;
  216. image{
  217. width: 100%;
  218. height: 100%;
  219. }
  220. }
  221. .content{
  222. box-sizing: border-box;
  223. background: #ffffff;
  224. border-radius: 8rpx 32rpx 8rpx 32rpx;
  225. margin: 24rpx 58rpx 0;
  226. padding: 24rpx 24rpx 40rpx;
  227. image{
  228. width: 596rpx;
  229. height: 800rpx;
  230. width: 100%;
  231. border-radius: 8rpx 20rpx 8rpx 0;
  232. }
  233. .poster{
  234. position: relative;
  235. }
  236. .code{
  237. position: absolute;
  238. right: 33rpx;
  239. bottom: 41rpx;
  240. image{
  241. width: 120rpx;
  242. height: 120rpx;
  243. }
  244. }
  245. .title{
  246. display: flex;
  247. justify-content: space-between;
  248. // align-items: center;
  249. font-size: 30rpx;
  250. font-weight: 600;
  251. color: #333333;
  252. margin: 32rpx 0 16rpx;
  253. .kangyang{
  254. word-break:break-all;//英文
  255. // padding-right: 20rpx;
  256. width: 400rpx;
  257. }
  258. }
  259. }
  260. .flex{
  261. box-sizing: border-box;
  262. margin: 90rpx 144rpx 0;
  263. display: flex;
  264. align-content: center;
  265. justify-content: space-between;
  266. .text{
  267. font-size: 20rpx;
  268. font-family: PingFang-SC-Medium, PingFang-SC;
  269. font-weight: 500;
  270. color: #666666;
  271. text-align: center;
  272. margin: 30rpx 0;
  273. }
  274. .weix{
  275. button::after {
  276. border: none;
  277. }
  278. image{
  279. width: 74rpx;
  280. height: 74rpx;
  281. }
  282. }
  283. .xiangc{
  284. image{
  285. width: 74rpx;
  286. height: 74rpx;
  287. }
  288. }
  289. }
  290. </style>