poster.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. if (!res.authSetting["scope.writePhotosAlbum"]) {
  118. //向用户发起授权请求
  119. uni.authorize({
  120. scope: "scope.writePhotosAlbum",
  121. success: () => {
  122. //授权成功保存图片到系统相册
  123. uni.downloadFile({
  124. url: this.imgurl,
  125. success: (res) => {
  126. console.log(res)
  127. if (res.statusCode === 200) {
  128. uni.saveImageToPhotosAlbum({
  129. filePath: res.tempFilePath,
  130. success: function() {
  131. uni.showToast({
  132. title: "保存成功",
  133. icon: "none"
  134. });
  135. },
  136. fail: function() {
  137. uni.showToast({
  138. title: "保存失败",
  139. icon: "none"
  140. });
  141. }
  142. });
  143. }
  144. }
  145. })
  146. },
  147. //授权失败
  148. fail: () => {
  149. uni.hideLoading();
  150. uni.showModal({
  151. title: "您已拒绝获取相册权限",
  152. content: "是否进入权限管理,调整授权?",
  153. success: (res) => {
  154. if (res.confirm) {
  155. //调起客户端小程序设置界面,返回用户设置的操作结果。(重新让用户授权)
  156. uni.openSetting({
  157. success: (res) => {
  158. console.log(res.authSetting);
  159. },
  160. });
  161. } else if (res.cancel) {
  162. return uni.showToast({
  163. title: "已取消!",
  164. });
  165. }
  166. },
  167. });
  168. },
  169. });
  170. } else {
  171. //如果已有相册权限,直接保存图片到系统相册
  172. uni.downloadFile({
  173. url:this.imgurl,
  174. success: (res) => {
  175. console.log(res)
  176. if (res.statusCode === 200) {
  177. uni.saveImageToPhotosAlbum({
  178. filePath: res.tempFilePath,
  179. success: function() {
  180. uni.showToast({
  181. title: "保存成功",
  182. icon: "none"
  183. });
  184. },
  185. fail: function() {
  186. uni.showToast({
  187. title: "保存失败",
  188. icon: "none"
  189. });
  190. }
  191. });
  192. }
  193. }
  194. })
  195. }
  196. },
  197. fail: (res) => {},
  198. });
  199. },
  200. }
  201. }
  202. </script>
  203. <style lang="less">
  204. page{
  205. background-color: #F4F4F4;
  206. }
  207. .imgbox{
  208. margin: 20rpx auto;
  209. width: 624rpx;
  210. height: 960rpx;
  211. image{
  212. width: 100%;
  213. height: 100%;
  214. }
  215. }
  216. .content{
  217. box-sizing: border-box;
  218. background: #ffffff;
  219. border-radius: 8rpx 32rpx 8rpx 32rpx;
  220. margin: 24rpx 58rpx 0;
  221. padding: 24rpx 24rpx 40rpx;
  222. image{
  223. width: 596rpx;
  224. height: 800rpx;
  225. width: 100%;
  226. border-radius: 8rpx 20rpx 8rpx 0;
  227. }
  228. .poster{
  229. position: relative;
  230. }
  231. .code{
  232. position: absolute;
  233. right: 33rpx;
  234. bottom: 41rpx;
  235. image{
  236. width: 120rpx;
  237. height: 120rpx;
  238. }
  239. }
  240. .title{
  241. display: flex;
  242. justify-content: space-between;
  243. // align-items: center;
  244. font-size: 30rpx;
  245. font-weight: 600;
  246. color: #333333;
  247. margin: 32rpx 0 16rpx;
  248. .kangyang{
  249. word-break:break-all;//英文
  250. // padding-right: 20rpx;
  251. width: 400rpx;
  252. }
  253. }
  254. }
  255. .flex{
  256. box-sizing: border-box;
  257. margin: 90rpx 144rpx 0;
  258. display: flex;
  259. align-content: center;
  260. justify-content: space-between;
  261. .text{
  262. font-size: 20rpx;
  263. font-family: PingFang-SC-Medium, PingFang-SC;
  264. font-weight: 500;
  265. color: #666666;
  266. text-align: center;
  267. margin: 30rpx 0;
  268. }
  269. .weix{
  270. button::after {
  271. border: none;
  272. }
  273. image{
  274. width: 74rpx;
  275. height: 74rpx;
  276. }
  277. }
  278. .xiangc{
  279. image{
  280. width: 74rpx;
  281. height: 74rpx;
  282. }
  283. }
  284. }
  285. </style>