share-boxN.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <view class="share-content" :style="{'width':viewWidth+'px'}">
  3. <view class="share-inner" style="width: 100%;">
  4. <view class="share-item" :style="{'width':viewWidth/viewCount+'px'}" @click="wxShare(0)">
  5. <image class="image" src="/static/images/icon_wx.png" mode=""></image>
  6. <text class="text">微信</text>
  7. </view>
  8. <view class="share-item" :style="{'width':viewWidth/viewCount+'px'}" @click="wxShare(1)">
  9. <image class="image" src="/static/images/icon_pyq.png" mode=""></image>
  10. <text class="text">朋友圈</text>
  11. </view>
  12. <view class="share-item" :style="{'width':viewWidth/viewCount+'px'}" @click="qwShare()">
  13. <image class="image" src="/static/images/icon_qwshare.png" mode=""></image>
  14. <text class="text">发给同事</text>
  15. </view>
  16. <!-- <view class="share-item" :style="{'width':viewWidth/viewCount+'px'}" @click="copyUrl()" v-if="operate.indexOf('copyUrl') > -1">
  17. <image class="image" src="/static/images/icon_copy_link.png" mode=""></image>
  18. <text class="text">复制链接</text>
  19. </view> -->
  20. <view class="share-item tsjy" :style="{'width':viewWidth/viewCount+'px'}" @click="goToFeedback()">
  21. <image class="image" src="/static/image/my/tsjy.png" mode=""></image>
  22. <text class="text">举报</text>
  23. </view>
  24. </view>
  25. <text class="cancel-btn" @click="closeShare">取消</text>
  26. </view>
  27. </template>
  28. <script>
  29. import {shareCourse} from '@/api/course'
  30. import { shareVideo } from '@/api/shortvideo'
  31. import { getQwCompanyList } from '@/api/common.js'
  32. import { registerQW,isAgreePrivacy } from '@/utils/common.js'
  33. export default {
  34. name: "share-box",
  35. props: {
  36. shareItem: {
  37. type: Object,
  38. default: function() {
  39. return {
  40. imageUrl: "",
  41. title: "",
  42. url: "",
  43. summary: url,
  44. courseId: 0,
  45. videoId: 0,
  46. isMini: false,
  47. compressImage: 0, // 是否需要压缩
  48. showReport:false,
  49. }; // type 0:课程 1视频
  50. }
  51. },
  52. operate: {
  53. type: Array,
  54. default:['WXSceneSession','WXSceneTimeline','copyUrl']
  55. }
  56. },
  57. data() {
  58. return {
  59. viewWidth: 0,
  60. viewCount:4.0,
  61. companyList:[]
  62. };
  63. },
  64. mounted() {
  65. const systemInfo = uni.getSystemInfoSync();
  66. this.viewWidth = systemInfo.screenWidth;
  67. if(this.shareItem.showReport){
  68. this.viewCount=5.2;
  69. }
  70. },
  71. methods: {
  72. wxShare(type) {
  73. if (this.isEmpty(this.shareItem.title)) {
  74. uni.showToast({
  75. title: "数据未加载",
  76. icon: "none",
  77. position: 'top',
  78. duration: 2000
  79. })
  80. return;
  81. }
  82. // #ifdef APP-PLUS
  83. if (!this.isAgreePrivacy()) {
  84. uni.showToast({
  85. title: "请同意隐私政策",
  86. icon: "none",
  87. position: 'top',
  88. duration: 2000
  89. })
  90. return;
  91. }
  92. // #endif
  93. let that = this;
  94. let sceneStr = type == 0 ? "WXSceneSession" : "WXSceneTimeline";
  95. // 仅支持分享微信小程序到微信聊天界面,想进入朋友圈需改为分享图片方式,在图片中包含小程序码
  96. if (sceneStr == 'WXSceneTimeline' || !this.shareItem.isMini) {
  97. uni.share({
  98. provider: "weixin",
  99. scene: sceneStr,
  100. type: 0,
  101. imageUrl: this.shareItem.imageUrl, //分享封面图片
  102. title: this.shareItem.title, // 分享标题
  103. href: this.shareItem.url, //跳转链接
  104. summary: this.shareItem.summary, // 分享内容文字
  105. success: function(res) {
  106. that.doShare();
  107. uni.showToast({
  108. title: "分享成功",
  109. icon: 'none'
  110. });
  111. },
  112. fail: function(err) {
  113. // 此处是调起微信分享失败的回调
  114. },
  115. complete: (e) => {
  116. console.log("WXSceneTimeline", e)
  117. }
  118. });
  119. } else {
  120. if(this.shareItem.compressImage == 1) {
  121. uni.downloadFile({
  122. url: this.shareItem.imageUrl, //仅为示例,并非真实接口地址。
  123. success: (images)=> {
  124. uni.compressImage({
  125. src: images.tempFilePath,
  126. quality: 40,
  127. width: '50%',
  128. height: '50%',
  129. success: res => {
  130. this.shareMini(res.tempFilePath,sceneStr)
  131. },
  132. fail: function(err) {
  133. // 此处是压缩失败
  134. }
  135. })
  136. }
  137. });
  138. } else {
  139. this.shareMini(this.shareItem.imageUrl)
  140. }
  141. }
  142. },
  143. shareMini(imageUrl,sceneStr) {
  144. const that = this
  145. uni.share({
  146. provider: "weixin",
  147. scene: sceneStr,
  148. type: 5,
  149. imageUrl: imageUrl, //分享封面图片
  150. title: this.shareItem.title, // 分享标题
  151. //summary: this.shareItem.summary, // 分享内容文字
  152. miniProgram: {
  153. id: "gh_feb7753a310b",//gh_7a6a32e5ef61 御君方互医
  154. path: this.shareItem.path,
  155. type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
  156. webUrl: "http://uniapp.dcloud.io"
  157. },
  158. success: function(res) {
  159. that.doShare();
  160. uni.showToast({
  161. title: "分享成功",
  162. icon: 'none'
  163. });
  164. },
  165. fail: function(err) {
  166. // 此处是调起微信分享失败的回调
  167. },
  168. complete: (e) => {
  169. console.log("WXSceneSession", e)
  170. }
  171. });
  172. },
  173. doShare() {
  174. if (!this.shareItem.isMini) {
  175. if (this.shareItem.courseId > 0) {
  176. this.shareCourse();
  177. }
  178. }
  179. if(this.shareItem.videoId > 0) {
  180. this.shareVideo();
  181. }
  182. },
  183. isEmpty(obj) {
  184. if (typeof obj == "undefined" || obj == null || obj == "") {
  185. return true;
  186. } else {
  187. return false;
  188. }
  189. },
  190. shareCourse() {
  191. shareCourse(this.shareItem.courseId).then(res => {
  192. },
  193. rej => {}
  194. );
  195. },
  196. shareVideo() {
  197. shareVideo({videoId:this.shareItem.videoId})
  198. },
  199. copyUrl() {
  200. uni.setClipboardData({
  201. data: this.shareItem.url,
  202. success: () => {
  203. uni.showToast({
  204. title: '复制成功',
  205. icon: 'none'
  206. });
  207. },
  208. fail: () => {
  209. uni.showToast({
  210. title: '复制失败',
  211. icon: 'none'
  212. });
  213. }
  214. });
  215. },
  216. closeShare() {
  217. return this.$emit('closeShare');
  218. },
  219. showToast(title) {
  220. uni.showToast({
  221. icon: 'none',
  222. title: title,
  223. duration: 3000
  224. });
  225. },
  226. qwShare() {
  227. if (this.isEmpty(this.shareItem.title)) {
  228. uni.showToast({
  229. title: "数据未加载",
  230. icon: "none",
  231. position: 'top',
  232. duration: 2000
  233. })
  234. return;
  235. }
  236. // #ifdef APP-PLUS
  237. if (!this.isAgreePrivacy()) {
  238. uni.showToast({
  239. title: "请同意隐私政策",
  240. icon: "none",
  241. position: 'top',
  242. duration: 2000
  243. })
  244. return;
  245. }
  246. // #endif
  247. console.log("qxj qwShare");
  248. this.getQwCompanyList();
  249. },
  250. getQwCompanyList(){
  251. let token = uni.getStorageSync('CompanyUserToken');
  252. if (!token) {
  253. uni.showToast({
  254. title: "请先登录销售账号",
  255. icon: 'none'
  256. });
  257. return
  258. }
  259. uni.showLoading()
  260. getQwCompanyList().then(res=>{
  261. uni.hideLoading()
  262. if(res.code == 200&&res.qwCompanyList&&res.qwCompanyList.length > 0) {
  263. this.companyList = res.qwCompanyList
  264. if(this.companyList.length==1) {
  265. this.initregisterQW(0)
  266. } else {
  267. uni.showActionSheet({
  268. itemList: this.companyList.map(item=>item.corpName),
  269. success: (res)=> {
  270. console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
  271. this.initregisterQW(res.tapIndex)
  272. },
  273. fail: (res)=> {
  274. console.log(res.errMsg);
  275. }
  276. });
  277. }
  278. } else {
  279. uni.showToast({
  280. title: "暂无可分享企业微信账号",
  281. icon: 'none'
  282. });
  283. }
  284. }).catch(()=>{
  285. uni.hideLoading()
  286. })
  287. },
  288. // 初始化注册到企业微信并分享
  289. initregisterQW(index) {
  290. getApp().globalData.shareSchema = this.companyList[index].yjfyySchema; //应用跳转标识,显示在具体应用下的 Schema字段
  291. getApp().globalData.shareCorpId = this.companyList[index].corpId; //企业唯一标识。创建企业后显示在,我的企业 CorpID字段
  292. getApp().globalData.shareAgentid = this.companyList[index].yjfyyAgentId; //应用
  293. getApp().globalData.shareAppid_gh = this.companyList[index].yjfyyAppId;
  294. registerQW((installed) => {
  295. this.doShare();
  296. this.$emit('closeShare')
  297. },this.shareItem)
  298. },
  299. goToFeedback(){
  300. uni.navigateTo({
  301. url: "/pages/user/feedback"
  302. });
  303. },
  304. isAgreePrivacy(){
  305. // #ifdef APP-PLUS
  306. const systemInfo = uni.getSystemInfoSync();
  307. let isAndroid = systemInfo.platform === 'android';
  308. if(isAndroid){
  309. return plus.runtime.isAgreePrivacy();
  310. }
  311. else{
  312. return true;
  313. }
  314. // #endif
  315. console.log("qxj isAgreePrivacy");
  316. return true;
  317. }
  318. }
  319. }
  320. </script>
  321. <style scoped lang="scss">
  322. .share-content {
  323. //border-radius: 40upx 40upx 0px 0px;
  324. width: 100%;
  325. height: auto; /* 改为自适应高度 */
  326. padding-bottom: 20rpx; /* 增加底部间距 */
  327. background: #fff;
  328. }
  329. .share-inner {
  330. padding: 20rpx 0; /* 增加上下内边距 */
  331. width: 100%;
  332. flex: 1;
  333. height: auto; /* 改为自适应高度 */
  334. flex-direction: row;
  335. flex-wrap: wrap;
  336. display: flex; /* 确保弹性布局生效 */
  337. }
  338. .share-item {
  339. /* width: 20%; 注释掉这行 */
  340. flex-direction: column;
  341. align-items: center;
  342. justify-content: center;
  343. height: 180rpx; /* 增加高度 */
  344. box-sizing: border-box;
  345. //flex: 1; /* 添加这个属性使5个项等宽 */
  346. min-width: 0; /* 防止内容溢出 */
  347. }
  348. .share-item .image {
  349. width: 80rpx;
  350. height: 80rpx;
  351. margin-top: 10rpx; /* 减少顶部间距 */
  352. }
  353. .share-item .text {
  354. font-size: 28rpx;
  355. font-weight: 500;
  356. color: #111111;
  357. height: auto; /* 改为自适应高度 */
  358. margin-top: 10rpx; /* 减少间距 */
  359. text-align: center; /* 文字居中 */
  360. white-space: nowrap; /* 防止文字换行 */
  361. }
  362. .tsjy .image {
  363. width: 48rpx;
  364. height: 48rpx;
  365. margin-top: 22rpx; /* 减少顶部间距 */
  366. }
  367. .tsjy .text {
  368. width: auto; /* 改为自适应宽度 */
  369. height: auto; /* 改为自适应高度 */
  370. margin-top: 30rpx; /* 减少间距 */
  371. }
  372. .cancel-btn {
  373. height: 90rpx; /* 增加高度 */
  374. line-height: 90rpx; /* 垂直居中 */
  375. text-align: center;
  376. font-size: 32upx;
  377. font-family: PingFang SC;
  378. font-weight: 500;
  379. color: #111111;
  380. border-top: 2upx solid #E8E8E8;
  381. background-color: #FFF;
  382. }
  383. </style>