| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- <template>
- <view class="share-content">
- <view class="share-inner">
- <view class="share-item" @click="wxShare(0)">
- <image src="/static/images/icon_wx.png" mode=""></image>
- <text class="text">微信</text>
- </view>
- <view class="share-item" @click="wxShare(1)">
- <image src="/static/images/icon_pyq.png" mode=""></image>
- <text class="text">朋友圈</text>
- </view>
- <!-- <view class="share-item" @click="qwShare()">
- <image src="/static/images/icon_qwshare.png" mode=""></image>
- <text class="text">发给同事</text>
- </view> -->
- <!-- <view class="share-item">
- <image src="/static/images/icon_xcxhb.png" mode=""></image>
- <text class="text">小程序海报</text>
- </view>
- <view class="share-item">
- <image src="/static/images/icon_xccard.png" mode=""></image>
- <text class="text">小程序卡片</text>
- </view>
- <view class="share-item">
- <image src="/static/images/icon_code.png" mode=""></image>
- <text class="text">二维码</text>
- </view> -->
- <view class="share-item" @click="copyUrl()">
- <image src="/static/images/icon_copy_link.png" mode=""></image>
- <text class="text">复制链接</text>
- </view>
- </view>
- <view class="cancel-btn" @click="closeShare">取消</view>
- </view>
- </template>
- <script>
- import {
- shareCourse
- } from '@/api/course'
- import {
- shareVideo
- } from '@/api/shortvideo'
- import {
- shareHealth
- } from '@/api/integral.js'
- import {
- getQwCompanyList
- } from '@/api/common.js'
- import {
- registerQW
- } from '@/utils/common.js'
- export default {
- name: "share-box",
- props: {
- shareItem: {
- type: Object,
- default: function() {
- return {
- imageUrl: "",
- title: "",
- url: "",
- summary: url,
- courseId: 0,
- videoId: 0,
- isMini: false,
- compressImage: 0, // 是否需要压缩
- }; // type 0:课程 1视频
- }
- },
- },
- data() {
- return {
- companyList: []
- };
- },
- methods: {
- wxShare(type) {
- if (this.$isEmpty(this.shareItem.title)) {
- uni.showToast({
- title: "数据未加载",
- icon: "none",
- position: 'top',
- duration: 2000
- })
- return;
- }
- // #ifdef APP-PLUS
- if (!plus.runtime.isAgreePrivacy() && uni.$u.os() === 'android') {
- uni.showToast({
- title: "请同意隐私政策",
- icon: "none",
- position: 'top',
- duration: 2000
- })
- return;
- }
- // #endif
- let that = this;
- let sceneStr = type == 0 ? "WXSceneSession" : "WXSceneTimeline";
- console.log("qxj shareItem:", this.shareItem);
- // 仅支持分享微信小程序到微信聊天界面,想进入朋友圈需改为分享图片方式,在图片中包含小程序码
- if (this.shareItem.yyb) {
- uni.share({
- provider: "weixin",
- scene: sceneStr,
- type: 0,
- imageUrl: this.shareItem.imageUrl, //分享封面图片
- title: this.shareItem.title, // 分享标题
- href: `https://a.app.qq.com/o/simple.jsp?pkgname=com.mytek.zklive&android_schema=${encodeURIComponent(this.shareItem.path)}`, //跳转链接
- summary: this.shareItem.summary, // 分享内容文字
- success: function(res) {
- that.doShare();
- uni.showToast({
- title: "分享成功",
- icon: 'none'
- });
- },
- fail: function(err) {
- // 此处是调起微信分享失败的回调
- },
- complete: (e) => {
- console.log("WXSceneTimeline", e)
- }
- });
- return
- }
- if (sceneStr == 'WXSceneTimeline' || !this.shareItem.isMini) {
- uni.share({
- provider: "weixin",
- scene: sceneStr,
- type: 0,
- imageUrl: this.shareItem.imageUrl, //分享封面图片
- title: this.shareItem.title, // 分享标题
- href: this.shareItem.url, //跳转链接
- summary: this.shareItem.summary, // 分享内容文字
- success: function(res) {
- that.doShare();
- uni.showToast({
- title: "分享成功",
- icon: 'none'
- });
- },
- fail: function(err) {
- // 此处是调起微信分享失败的回调
- },
- complete: (e) => {
- console.log("WXSceneTimeline", e)
- }
- });
- } else {
- if (this.shareItem.compressImage == 1) {
- this.shareMini(this.shareItem.imageUrl + "?imageMogr2/thumbnail/300x", sceneStr);
- // uni.downloadFile({
- // url: this.shareItem.imageUrl, //仅为示例,并非真实接口地址。
- // success: (images)=> {
- // uni.compressImage({
- // src: images.tempFilePath,
- // quality: 40,
- // width: '50%',
- // height: '50%',
- // success: res => {
- // this.shareMini(res.tempFilePath,sceneStr)
- // },
- // fail: function(err) {
- // // 此处是压缩失败
- // }
- // })
- // }
- // });
- } else {
- this.shareMini(this.shareItem.imageUrl, sceneStr)
- }
- }
- },
- shareMini(imageUrl, sceneStr) {
- const that = this
- uni.share({
- provider: "weixin",
- scene: sceneStr,
- type: 5,
- imageUrl: imageUrl, //分享封面图片
- title: this.shareItem.title, // 分享标题
- //summary: this.shareItem.summary, // 分享内容文字
- miniProgram: {
- id: getApp().globalData.miniprogamId,
- path: this.shareItem.path,
- type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
- webUrl: "http://uniapp.dcloud.io"
- },
- success: function(res) {
- that.doShare();
- uni.showToast({
- title: "分享成功",
- icon: 'none'
- });
- },
- fail: function(err) {
- // 此处是调起微信分享失败的回调
- },
- complete: (e) => {
- console.log("WXSceneSession", e)
- }
- });
- },
- doShare() {
- if (!this.shareItem.isMini) {
- if (this.shareItem.courseId > 0) {
- this.shareCourse();
- }
- }
- if (this.shareItem.videoId > 0) {
- this.shareVideo();
- } else if (this.shareItem.healthId > 0) {
- this.shareHealth();
- }
- },
- shareCourse() {
- shareCourse(this.shareItem.courseId).then(res => {
- },
- rej => {}
- );
- },
- shareVideo() {
- shareVideo({
- videoId: this.shareItem.videoId
- })
- },
- shareHealth() {
- shareHealth({
- logType: 3
- })
- },
- copyUrl() {
- uni.setClipboardData({
- data: this.shareItem.url,
- success: () => {
- uni.showToast({
- title: '复制成功',
- icon: 'none'
- });
- },
- fail: () => {
- uni.showToast({
- title: '复制失败',
- icon: 'none'
- });
- }
- });
- },
- closeShare() {
- return this.$emit('closeShare');
- },
- qwShare() {
- if (this.$isEmpty(this.shareItem.title)) {
- uni.showToast({
- title: "数据未加载",
- icon: "none",
- position: 'top',
- duration: 2000
- })
- return;
- }
- // #ifdef APP-PLUS
- if (!plus.runtime.isAgreePrivacy()) {
- uni.showToast({
- title: "请同意隐私政策",
- icon: "none",
- position: 'top',
- duration: 2000
- })
- return;
- }
- // #endif
- this.getQwCompanyList()
- },
- getQwCompanyList() {
- let token = uni.getStorageSync('CompanyUserToken');
- if (!token) {
- uni.showToast({
- title: "请先登录销售账号",
- icon: 'none'
- });
- return
- }
- uni.showLoading()
- getQwCompanyList().then(res => {
- uni.hideLoading()
- if (res.code == 200 && res.qwCompanyList && res.qwCompanyList.length > 0) {
- this.companyList = res.qwCompanyList
- if (this.companyList.length == 1) {
- this.initregisterQW(0)
- } else {
- uni.showActionSheet({
- itemList: this.companyList.map(item => item.corpName),
- success: (res) => {
- console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
- this.initregisterQW(res.tapIndex)
- },
- fail: (res) => {
- console.log(res.errMsg);
- }
- });
- }
- } else {
- uni.showToast({
- title: "暂无可分享企业微信账号",
- icon: 'none'
- });
- }
- }).catch(() => {
- uni.hideLoading()
- })
- },
- // 初始化注册到企业微信并分享
- initregisterQW(index) {
- getApp().globalData.shareSchema = this.companyList[index].yjfyySchema; //应用跳转标识,显示在具体应用下的 Schema字段
- getApp().globalData.shareCorpId = this.companyList[index].corpId; //企业唯一标识。创建企业后显示在,我的企业 CorpID字段
- getApp().globalData.shareAgentid = this.companyList[index].yjfyyAgentId; //应用
- getApp().globalData.shareAppid_gh = this.companyList[index].yjfyyAppId;
- registerQW((installed) => {
- this.doShare();
- this.$emit('closeShare')
- }, this.shareItem)
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .share-content {
- background-color: #FFF;
- border-radius: 40upx 40upx 0px 0px;
- .share-inner {
- padding: 70upx 0 0 0;
- display: flex;
- flex-wrap: wrap;
- .share-item {
- width: 25%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- margin-bottom: 66upx;
- image {
- width: 80upx;
- height: 80upx;
- margin-bottom: 20upx;
- }
- .text {
- font-size: 28upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #111111;
- line-height: 1;
- }
- }
- }
- .cancel-btn {
- height: 96upx;
- line-height: 96upx;
- text-align: center;
- font-size: 32upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #111111;
- border-top: 2upx solid #E8E8E8;
- background-color: #FFF;
- }
- }
- </style>
|