123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <template>
- <view class="content">
- <!-- <button type="primary" @tap="shareInfo">分享</button> -->
- </view>
- </template>
- <script>
- import $config from './../../config/global.config';
- import share from '@/common/share.js';
- export default {
- props: {},
- data() {
- return {
- title: 'Hello',
- avatarUrl: '',
- invitationCode: '',
- username: '',
- imgUrl: this.$mConfig.staticUrl
- };
- },
- onLoad() {},
- onShow() {},
- onBackPress() {
- //监听back键,关闭弹出菜单
- if (this.shareObj.shareMenu.isVisible()) {
- this.shareObj.shareMenu.hide();
- this.shareObj.alphaBg.hide();
- return true;
- }
- },
- methods: {
- //noHome 代表非首页,即自定义页面
- shareInfo(params, url, title, des, images, noHome = false) {
- // return this.$mUtil.toast('暂无法使用分享功能')
- console.log('params', params, url);
- let shareList = [{
- icon: '/static/czd/wx.png',
- text: '微信好友'
- },
- {
- icon: '/static/czd/pyq.png',
- text: '朋友圈'
- }
- ];
- let shareInfo = {
- href: $config.hostUrl,
- title: title || '"宜格服务"懂宜昌,更懂你!',
- summary: des || '打造宜昌政务、医疗、交通、旅游、教育、生活等综合城市服务平台!',
- imgUrl: images || '/logo.png'
- };
- /* if (!noHome) {
- let options = params.split('/?')[1].split('&');
- let pageType = options[0].split('=')[1];
- let type = options[1].split('=')[1];
- let model_id = options[2].split('=')[1];
- let model_type = null;
- if (pageType == 3) {
- model_type = 0;
- }
- if (pageType == 2) {
- model_type = 1;
- }
- if (pageType == 1) {
- if (type == 1 || type == 5) {
- model_type = 2;
- }
- if (type == 2) {
- model_type = 5;
- }
- if (type == 3) {
- model_type = 6;
- }
- if (type == 4) {
- model_type = 3;
- }
- }
- } */
- this.shareObj = share(shareInfo, shareList, index => {
- console.log('点击按钮的序号: ' + index);
- console.log('分享信息' + shareInfo.href, shareInfo.title, shareInfo.summary);
- if (index == 0) {
- uni.share({
- provider: 'weixin',
- scene: 'WXSceneSession',
- type: 0,
- href: shareInfo.href,
- title: shareInfo.title,
- summary: shareInfo.summary,
- imageUrl: shareInfo.imgUrl,
- success: res => {
- this.shareObj.shareMenu.hide();
- this.shareObj.alphaBg.hide();
- // this.cacheBbs(model_type, model_id);
- // this.$mUtil.toast('分享成功')
- },
- fail: (err) => {
- this.shareObj.shareMenu.hide();
- this.shareObj.alphaBg.hide();
- }
- });
- } else if (index == 1) {
- uni.share({
- provider: 'weixin',
- scene: 'WXSenceTimeline',
- type: 0,
- href: shareInfo.href,
- title: shareInfo.title,
- summary: shareInfo.summary,
- imageUrl: shareInfo.imgUrl,
- success: res => {
- this.shareObj.shareMenu.hide();
- this.shareObj.alphaBg.hide();
- // this.cacheBbs(model_type, model_id);
- },
- fail: (err) => {
- this.shareObj.shareMenu.hide();
- this.shareObj.alphaBg.hide();
- }
- });
- } else {
- this.shareObj.shareMenu.hide();
- this.shareObj.alphaBg.hide();
- }
- });
- this.$nextTick(() => {
- this.shareObj.alphaBg.show();
- this.shareObj.shareMenu.show();
- });
- },
- cacheBbs(model_type, model_id) {
- console.log('参数为' + model_type, model_id);
- this.$http
- .post(`/opus/cache-bbs`, {
- bbs_type: 2,
- model_type: model_type,
- model_id: model_id
- })
- .then(res => {});
- }
- }
- };
- </script>
- <style>
- .content {
- text-align: center;
- height: 400upx;
- }
- .logo {
- height: 200upx;
- width: 200upx;
- margin-top: 200upx;
- }
- .title {
- font-size: 36upx;
- color: #8f8f94;
- }
- </style>
|