Feat:分享接口对接&&换一换接口对接

This commit is contained in:
modendeveloper
2024-12-14 21:56:37 +08:00
parent b535e21e2f
commit eddb02d2cf
4 changed files with 193 additions and 11 deletions
+115 -3
View File
@@ -21,7 +21,7 @@
4A
</text>
</view>
<view class="shareBtn"><u-icon name="share-square" color="#C52733"></u-icon>分享给好友</view>
<view class="shareBtn" @click="shareImg"><u-icon name="share-square" color="#C52733"></u-icon>分享给好友</view>
<u-line dashed></u-line>
<view v-if="townInfo.intro" class="v12-pa-3 intro-content">
<u-read-more :toggle="true" showHeight="200">
@@ -47,11 +47,35 @@
</view>
</view>
<!-- 分享 -->
<u-popup
:show="showShare"
mode="center"
bgColor="transparent"
>
<view class="box-share">
<view class="box-img">
<image
:src="webUrl + '/20230608112219219303.png'"
class="icon"
@click="closeShare"
/>
<image :src="posterUrl" class="main-img" mode="widthFix" />
</view>
<image
:src="webUrl + '/20230608112210135038.png'"
mode="widthFix"
class="btn"
@click="saveImg"
/>
</view>
</u-popup>
</view>
</template>
<script>
import { getAncientTownInfo, getAncientTownActive } from "@/api/inn.js"
import { getAncientTownInfo, getAncientTownActive, shareTown } from "@/api/inn.js"
import {getUrlParam} from '@/utils/common.js'
import culture from './components/culture.vue'
import information from './components/information.vue'
import service from './components/service.vue'
@@ -65,7 +89,10 @@ export default {
},
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
showShare: false,
townInfo: {},
posterUrl: '',
activeties: [],
id: '',
actived: 1,
@@ -78,11 +105,95 @@ export default {
}
},
onLoad(opts) {
this.id = opts.id
this.id = opts.id
const obj = uni.getEnterOptionsSync()
if(opts.scene || obj.query.scene) {
const query = opts ? decodeURIComponent(opts.scene) : decodeURIComponent(obj.query.scene)
this.id = getUrlParam(query, 'id') || null
}
this.getInfo()
this.getActive()
},
methods: {
shareImg() {
uni.showLoading()
shareTown(this.id).then(res => {
this.posterUrl = res.data
this.showShare = !this.showShare
}).finally(() => {
uni.hideLoading()
})
},
closeShare() {
this.showShare = false
},
saveImg() {
const _this = this
uni.getSetting({
success: getRes => {
if (getRes.authSetting["scope.writePhotosAlbum"]) {
_this.downloadImage()
} else {
uni.authorize({
scope: "scope.writePhotosAlbum",
success: () => {
_this.downloadImage()
},
fail: () => {
uni.openSetting({
success: openRes => {
console.log(typeof openRes, openRes)
},
fail: () => {
uni.showToast({
title: "请在设置中打开对应权限",
icon: "none"
})
}
})
}
})
}
},
fail: (err) => {
console.log(err, 2)
}
})
},
downloadImage() {
const _this = this
const randomID = () => Math.random().toString(36).substring(2)
uni.downloadFile({
url: this.posterUrl, // 网络图片的地址
filePath: wx.env.USER_DATA_PATH + "/share_" + randomID() + ".png", // 指定的本地文件路径
success: downRes => {
uni.saveImageToPhotosAlbum({
filePath: downRes.filePath, // 临时文件地址
success: function () {
uni.showToast({
title: "保存成功",
icon: "success",
success() {
_this.showShare = false
}
})
},
fail: function (err) {
uni.showToast({
title: err,
icon: "none"
})
}
})
},
fail: function (err) {
uni.showToast({
title: err.errMsg,
icon: "error"
})
}
})
},
getInfo() {
uni.showLoading()
getAncientTownInfo(this.id).then(res => {
@@ -107,6 +218,7 @@ export default {
</script>
<style lang="less" scoped>
@import "@/assets/css/store.less";
.shareBtn{
width: fit-content;
padding: 5rpx 15rpx;