Commit b0eb3b05 authored by 郭志伟's avatar 郭志伟

feat(share): 功能完成

parent 7a3b2a14
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
return http.get(`${config.apiHost}/editor/get/${params.pageId}`); return http.get(`${config.apiHost}/editor/get/${params.pageId}`);
}, },
getMpSchema(params) { getMpSchema(params) {
return http.post(`${config.kdspHost}/api/kdsp/ka/info/getShareMiniUrl`); return http.post(`http://talos-vcc3.liangkebang.net/api/kdsp/ka/info/getShareMiniUrl`, params);
}, },
getWxConfig(url = window.location.href.split('#')[0]) { getWxConfig(url = window.location.href.split('#')[0]) {
return http.post(`${config.kdspHost}/api/kdsp/wx/mp/getJsapiSign`, { return http.post(`${config.kdspHost}/api/kdsp/wx/mp/getJsapiSign`, {
......
...@@ -21,11 +21,11 @@ if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') ...@@ -21,11 +21,11 @@ if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production')
.install(); .install();
} }
// if (EASY_ENV_IS_BROWSER && process.env.SENTRY_ENV === 'test' || process.env.NODE_ENV !== 'production') { if (EASY_ENV_IS_BROWSER) {
// // ! 上线后务必取掉; // ! 上线后务必取掉;
// const vConsole = require('vconsole'); const vConsole = require('vconsole');
// new vConsole(); new vConsole();
// } }
if (EASY_ENV_IS_BROWSER) { if (EASY_ENV_IS_BROWSER) {
const isSafari = /^.*((iPhone)|(iPad)|(Safari))+.*$/; const isSafari = /^.*((iPhone)|(iPad)|(Safari))+.*$/;
...@@ -40,6 +40,7 @@ if (EASY_ENV_IS_BROWSER) { ...@@ -40,6 +40,7 @@ if (EASY_ENV_IS_BROWSER) {
Vue.use(lazyload); Vue.use(lazyload);
const saDirective = new SaDirective(); const saDirective = new SaDirective();
Vue.directive('track', saDirective.directive); Vue.directive('track', saDirective.directive);
Vue.config.ignoredElements = ['wx-open-launch-weapp', 'wx-open-launch-app'];
window.xyqbNativeEvent = function(res) { window.xyqbNativeEvent = function(res) {
const json = typeof res === 'string' ? JSON.parse(res) : res; const json = typeof res === 'string' ? JSON.parse(res) : res;
console.log('xyqbNativeEvent toggle'); console.log('xyqbNativeEvent toggle');
......
import Vue from 'vue'; import Vue from 'vue';
import { sync } from 'vuex-router-sync'; import { sync } from 'vuex-router-sync';
import api from '@/api/editor.api';
import { isWechat } from '@/service/utils.service';
import initService from '@/service/init.service'; import initService from '@/service/init.service';
export default class App { export default class App {
config: any; config: any;
...@@ -25,6 +27,7 @@ export default class App { ...@@ -25,6 +27,7 @@ export default class App {
const { initSa } = require('@/service/sa.service'); const { initSa } = require('@/service/sa.service');
initService.init(router); initService.init(router);
initSa(router); initSa(router);
this.setWxConfig();
} }
return { return {
router, router,
...@@ -35,6 +38,18 @@ export default class App { ...@@ -35,6 +38,18 @@ export default class App {
}; };
} }
async setWxConfig() {
if (!isWechat) { return; }
const wx = require('weixin-js-sdk');
const [res] = await api.getWxConfig();
wx.config({
debug: false,
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'], // 必填,需要使用的JS接口列表
openTagList: ['wx-open-launch-weapp', 'wx-open-launch-app'],
...res
});
}
fetch(vm): Promise<any> { fetch(vm): Promise<any> {
const { store, router } = vm; const { store, router } = vm;
const matchedComponents = router.getMatchedComponents(); const matchedComponents = router.getMatchedComponents();
......
<template>
<wx-open-launch-app
class="launch-btn"
@launch="launch"
@error="launchError"
id="launch-btn"
appid="wx75d5a207551d0b4d"
:extinfo="extinfo"
>
<script type="text/wxtag-template">
<style>.btn {height: 100vh;width: 100vw;}</style>
<div class="btn">打开APP</div>
</script>
</wx-open-launch-app>
</template>
<script>
import { navToDlApp } from '@qg/citrus-ui/src/helper/service/utils';
export default {
name: "LaunchApp",
props: {
jumpUrl: String,
appSchema: String
},
computed: {
extinfo() {
return JSON.stringify({
url: this.jumpUrl,
data: {}
});
}
},
methods: {
launch() {
setTimeout(() => {
navToDlApp();
}, 2500);
window.location.href = this.appSchema;
},
launchError(e) {
if (e.detail.errMsg === "launch:fail") {
navToDlApp();
}
},
}
};
</script>
<style lang="less">
.launch-btn {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
opacity: 0;
z-index: 100;
left: 0;
}
</style>
...@@ -7,35 +7,21 @@ ...@@ -7,35 +7,21 @@
@error="launchError" @error="launchError"
> >
<script type="text/wxtag-template"> <script type="text/wxtag-template">
<style>.btn {height: 96px}</style> <style>.btn {height: 100vh;width: 100vw;}</style>
<div class="btn">打开小程序</div> <div class="btn">打开小程序</div>
</script> </script>
</wx-open-launch-weapp> </wx-open-launch-weapp>
</template> </template>
<script> <script>
import wx from "weixin-js-sdk";
import api from '@/api/editor.api';
export default { export default {
name: "Weapp", name: "LaunchWeapp",
props: { props: {
jumpUrl: String jumpUrl: String
}, },
data() { data() {
return {}; return {};
}, },
created() {
this.wxConfig();
},
methods: { methods: {
async wxConfig() {
const [res] = await api.getWxConfig();
wx.config({
debug: false,
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"], // 必填,需要使用的JS接口列表
openTagList: ["wx-open-launch-weapp"],
...res
});
},
launch() { launch() {
console.log("launch"); console.log("launch");
}, },
......
<template> <template>
<div> <div>
<cr-back-top :show-back-top="showBackTop && pageData.props.showBackTop" :list="backTopList" @click="handleBackTopClick" ref="crBackTop" /> <cr-back-top :show-back-top="showTop" :list="backTopList" @click="handleBackTopClick" ref="crBackTop" />
<cr-popover <cr-popover
class="wxmp-tip" class="wxmp-tip"
:value="showMpTip" :value="showMpTip"
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
</div> </div>
<template #reference>提示</template> <template #reference>提示</template>
</cr-popover> </cr-popover>
<div v-if="showShareOverlay" class="share-overlay" @click="onShareOverlayClick"> <div v-if="showShareOverlay" class="share-overlay" @click.self="onShareOverlayClick">
<we-app :jump-url="mpLink" v-if="isWechat" /> <launch-weapp :jump-url="mpSchema" v-if="isWechat && shareOpenMethod === 1" />
<launch-app :jump-url="link" app-schema="appSchema" v-if="isWechat && shareOpenMethod === 2" />
</div> </div>
</div> </div>
...@@ -20,9 +21,10 @@ ...@@ -20,9 +21,10 @@
<script> <script>
import Bridge from '@qg/js-bridge'; import Bridge from '@qg/js-bridge';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { isApp, isWxMp, isWechat } from '@/service/utils.service'; import { isApp, isWxMp, isWechat, isH5Normal } from '@/service/utils.service';
import api from '@/api/editor.api'; import api from '@/api/editor.api';
import WeApp from './components/weapp.vue'; import LaunchWeapp from './components/LaunchWeapp.vue';
import LaunchApp from './components/LaunchApp.vue';
const SHARE_CONFIG = { const SHARE_CONFIG = {
name: 'share', name: 'share',
txt: '', txt: '',
...@@ -32,23 +34,12 @@ const SHARE_CONFIG = { ...@@ -32,23 +34,12 @@ const SHARE_CONFIG = {
export default { export default {
name: 'BackTop', name: 'BackTop',
components: { components: {
WeApp LaunchWeapp,
LaunchApp
}, },
props: { props: {
showBackTop: Boolean showBackTop: Boolean
}, },
computed: {
...mapGetters(['pageData']),
...mapGetters(['pageInfo']),
backTopList() {
if (this.pageData && this.pageData.props && this.pageData.props.btAttachVal) {
const { btAttachVal, showShare } = this.pageData.props;
showShare && btAttachVal.push(SHARE_CONFIG);
return btAttachVal;
}
return [];
}
},
data() { data() {
return { return {
renderTpl: false, renderTpl: false,
...@@ -57,38 +48,59 @@ export default { ...@@ -57,38 +48,59 @@ export default {
jsBridge: null, jsBridge: null,
wx: null, wx: null,
mpSchema: '', mpSchema: '',
mpLink: '', link: '',
shareInfo: {},
showShareOverlay: isWechat || isH5Normal, showShareOverlay: isWechat || isH5Normal,
isWechat isWechat
}; };
}, },
computed: { computed: {
...mapGetters(['pageData', 'pageInfo']),
showTop() {
return this.showBackTop && this.pageData.props && this.pageData.props.showBackTop;
},
backTopList() {
if (this.pageData.props && this.pageData.props.btAttachVal) {
const { btAttachVal, showShare } = this.pageData.props;
showShare && btAttachVal.push(SHARE_CONFIG);
return btAttachVal;
}
return [];
},
appSchema() { appSchema() {
return `xyqb://openhttp?jumpurl=${this.mpLink}`; return `xyqb://openhttp?jumpurl=${this.link}`;
},
shareOpenMethod() {
return this.pageInfo.shareOpenMethod;
} }
}, },
created() { created() {
if (!EASY_ENV_IS_NODE) { if (!EASY_ENV_IS_NODE) {
this.renderTpl = true; this.renderTpl = true;
this.jsBridge = new Bridge(); this.jsBridge = new Bridge();
this.wx = require('weixin-js-sdk'); this.link = `${window.location.origin}${window.location.pathname}?vccToken={token}&vccChannel={registerFrom}`;
this.mpLink = `${window.location.origin}${window.location.pathname}?vccToken={token}&vccChannel={registerFrom}`;
this.getMpSchema(); this.getMpSchema();
this.initShareInfo();
} }
}, },
methods: { methods: {
async getMpSchema() { async getMpSchema() {
if (isH5Normal && EASY_ENV_IS_BROWSER) { if (isH5Normal && EASY_ENV_IS_BROWSER) {
try {
const [schema] = await api.getMpSchema({ const [schema] = await api.getMpSchema({
miniUrl: 'pages/webview/webview', miniUrl: 'pages/webview',
params: `url=${encodeURIComponent(JSON.stringify(this.mpLink))}` params: `url=${encodeURIComponent(JSON.stringify(this.link))}`
}); });
this.mpSchema = schema.nextUrl; this.mpSchema = schema;
} catch (error) {
}
} }
}, },
onShareOverlayClick() { onShareOverlayClick() {
if (isH5Normal) { if (isH5Normal) {
window.location.href = this.pageInfo.shareOpenMethod === 1 ? this.mpSchema : this.appSchema; window.location.href = this.shareOpenMethod === 1 ? this.mpSchema : this.appSchema;
} }
}, },
handleBackTopClick(e) { handleBackTopClick(e) {
...@@ -102,11 +114,11 @@ export default { ...@@ -102,11 +114,11 @@ export default {
}, 600); }, 600);
} }
}, },
share() { initShareInfo() {
if (EASY_ENV_IS_NODE) return; if (EASY_ENV_IS_NODE) return;
const { coverImage, pageName, pageDescribe, shareCoverImage } = this.pageInfo; const { coverImage, pageName, pageDescribe, shareCoverImage } = this.pageInfo;
const link = `${window.location.origin}${window.location.pathname}?vccToken={token}&vccChannel={registerFrom}`; const link = `${window.location.origin}${window.location.pathname}?vccToken={token}&vccChannel={registerFrom}`;
const data = { this.shareInfo = {
event: "showShareView", event: "showShareView",
data: { data: {
platform: ["weChat",  "CopyLink"], platform: ["weChat",  "CopyLink"],
...@@ -118,17 +130,28 @@ export default { ...@@ -118,17 +130,28 @@ export default {
} }
} }
}; };
if (isWxMp) {
this.postMpShareInfo();
}
},
share() {
if (EASY_ENV_IS_NODE) return;
if (isApp) { if (isApp) {
this.appShare(data); this.appShare();
} else if (isWxMp) { } else if (isWxMp) {
this.mpShare(data); this.mpShare();
} }
}, },
appShare(data) { appShare() {
this.jsBridge.showShareView(data); this.jsBridge.showShareView(this.shareInfo);
},
postMpShareInfo() {
if (EASY_ENV_IS_NODE) return;
const wx = require('weixin-js-sdk');
const { shareInfo } = this;
wx.miniProgram.postMessage({ data: shareInfo });
}, },
mpShare(data) { mpShare() {
this.wx.miniProgram.postMessage(data);
this.showMpTip = true; this.showMpTip = true;
setTimeout(() => { setTimeout(() => {
this.showMpTip = false; this.showMpTip = false;
......
...@@ -12,6 +12,7 @@ export default class FreedomContainer extends Mixins(TransformStyleMixin, SaMixi ...@@ -12,6 +12,7 @@ export default class FreedomContainer extends Mixins(TransformStyleMixin, SaMixi
@Prop({type: Object, default: () => ({ child: [] })}) childItem; @Prop({type: Object, default: () => ({ child: [] })}) childItem;
@Prop({type: Object, default: () => ({})}) saInfo; @Prop({type: Object, default: () => ({})}) saInfo;
@Prop(String) link;
@Prop(String) backgroundImage; @Prop(String) backgroundImage;
mounted() { mounted() {
...@@ -24,4 +25,5 @@ export default class FreedomContainer extends Mixins(TransformStyleMixin, SaMixi ...@@ -24,4 +25,5 @@ export default class FreedomContainer extends Mixins(TransformStyleMixin, SaMixi
// }); // });
// } // }
} }
} }
<template> <template>
<div class="freedom" v-track> <div class="freedom" v-track="{ link }">
<div class="freedom-body"> <div class="freedom-body">
<component :class="['freedom-body-item', { 'Fb-item_selected': curChildIndex === index }]" v-for="(item, index) in childItem.child" :style="transformStyle(item.commonStyle, 'container')" :is="item.name" :key="index" :sa-info="getSaInfo(item)" v-bind="item.props"></component> <component :class="['freedom-body-item', { 'Fb-item_selected': curChildIndex === index }]" v-for="(item, index) in childItem.child" :style="transformStyle(item.commonStyle, 'container')" :is="item.name" :key="index" :sa-info="getSaInfo(item)" v-bind="item.props"></component>
</div> </div>
......
...@@ -1638,9 +1638,9 @@ ...@@ -1638,9 +1638,9 @@
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==" "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
}, },
"@popperjs/core": { "@popperjs/core": {
"version": "2.9.2", "version": "2.10.1",
"resolved": "http://npmprivate.quantgroups.com/@popperjs%2fcore/-/core-2.9.2.tgz", "resolved": "http://npmprivate.quantgroups.com/@popperjs%2fcore/-/core-2.10.1.tgz",
"integrity": "sha512-VZMYa7+fXHdwIq1TDhSXoVmSPEGM/aa+6Aiq3nVVJ9bXr24zScr+NlKFKC3iPljA7ho/GAZr+d2jOf5GIRC30Q==" "integrity": "sha1-co7NlasgequKmk5CHwQi2zKSMr4="
}, },
"@qg/apollo-nodejs": { "@qg/apollo-nodejs": {
"version": "2.1.2", "version": "2.1.2",
...@@ -1648,9 +1648,9 @@ ...@@ -1648,9 +1648,9 @@
"integrity": "sha512-uOCUKu5mvX3PWee+7ZFXQSNIR1V5SN2JVE2yANmW9/wQOgpEct291gXGok8VMw0009HlTWB4JATURPwyOP2DFg==" "integrity": "sha512-uOCUKu5mvX3PWee+7ZFXQSNIR1V5SN2JVE2yANmW9/wQOgpEct291gXGok8VMw0009HlTWB4JATURPwyOP2DFg=="
}, },
"@qg/cherry-ui": { "@qg/cherry-ui": {
"version": "2.21.1", "version": "2.23.6",
"resolved": "http://npmprivate.quantgroups.com/@qg%2fcherry-ui/-/cherry-ui-2.21.1.tgz", "resolved": "http://npmprivate.quantgroups.com/@qg%2fcherry-ui/-/cherry-ui-2.23.6.tgz",
"integrity": "sha512-OQ9njfH6cs6FaNqPb7W+hEe/yftpdLXyjGXo2g4IwY7o/9Z5EH6Bn6B5X6dFGOka7LSyXyWRSfZzX0upIIpDFw==", "integrity": "sha512-jKv/DMHaaQyba/yR3LUdY1lVhkLjcv9hb5o5ri/jb3Xhi7mglhdAeCEFmYyyKu1QXLbGZQdGKuYsfz5o87SJcQ==",
"requires": { "requires": {
"@popperjs/core": "^2.5.4", "@popperjs/core": "^2.5.4",
"vue-lazyload": "^1.3.3", "vue-lazyload": "^1.3.3",
...@@ -1658,12 +1658,12 @@ ...@@ -1658,12 +1658,12 @@
} }
}, },
"@qg/citrus-ui": { "@qg/citrus-ui": {
"version": "0.2.27", "version": "0.2.28",
"resolved": "http://npmprivate.quantgroups.com/@qg%2fcitrus-ui/-/citrus-ui-0.2.27.tgz", "resolved": "http://npmprivate.quantgroups.com/@qg%2fcitrus-ui/-/citrus-ui-0.2.28.tgz",
"integrity": "sha512-RQWArNw0AVF/am50n0heECgqtFxeeG2wvYzwZSmWf0zRwOpqyad32lnFp32pgUgVZfLkNuOVW7klJzbKYMFPKA==", "integrity": "sha512-uW9D2e7bs2Otkvum6ph0c11CkY2kZMzJTHLIBK8Jq1VmGBhCjjWOsy+wVYLHfc82sy/WtJ93Jyt/y4MUAfHrQg==",
"requires": { "requires": {
"@better-scroll/core": "^2.1.1", "@better-scroll/core": "^2.1.1",
"@qg/cherry-ui": "^2.21.1", "@qg/cherry-ui": "^2.23.6",
"@qg/js-bridge": "^1.1.11", "@qg/js-bridge": "^1.1.11",
"axios": "^0.21.1", "axios": "^0.21.1",
"intersection-observer": "^0.12.0", "intersection-observer": "^0.12.0",
...@@ -8362,9 +8362,9 @@ ...@@ -8362,9 +8362,9 @@
} }
}, },
"es5-shim": { "es5-shim": {
"version": "4.5.15", "version": "4.6.2",
"resolved": "http://npmprivate.quantgroups.com/es5-shim/-/es5-shim-4.5.15.tgz", "resolved": "http://npmprivate.quantgroups.com/es5-shim/-/es5-shim-4.6.2.tgz",
"integrity": "sha512-FYpuxEjMeDvU4rulKqFdukQyZSTpzhg4ScQHrAosrlVpR6GFyaw14f74yn2+4BugniIS0Frpg7TvwZocU4ZMTw==" "integrity": "sha1-gnzdDG+1vrJv02jWVDDoterrqUI="
}, },
"es6-iterator": { "es6-iterator": {
"version": "2.0.3", "version": "2.0.3",
...@@ -18814,9 +18814,9 @@ ...@@ -18814,9 +18814,9 @@
} }
}, },
"parse-headers": { "parse-headers": {
"version": "2.0.3", "version": "2.0.4",
"resolved": "http://npmprivate.quantgroups.com/parse-headers/-/parse-headers-2.0.3.tgz", "resolved": "http://npmprivate.quantgroups.com/parse-headers/-/parse-headers-2.0.4.tgz",
"integrity": "sha512-QhhZ+DCCit2Coi2vmAKbq5RGTRcQUOE2+REgv8vdyu7MnYx2eZztegqtTx99TZ86GTIwqiy3+4nQTWZ2tgmdCA==" "integrity": "sha512-psZ9iZoCNFLrgRjZ1d8mn0h9WRqJwFxM9q3x7iUjN/YT2OksthDJ5TiPCu2F38kS4zutqfW+YdVVkBZZx3/1aw=="
}, },
"parse-json": { "parse-json": {
"version": "4.0.0", "version": "4.0.0",
...@@ -20930,9 +20930,9 @@ ...@@ -20930,9 +20930,9 @@
} }
}, },
"sa-sdk-javascript": { "sa-sdk-javascript": {
"version": "1.18.17", "version": "1.18.18",
"resolved": "http://npmprivate.quantgroups.com/sa-sdk-javascript/-/sa-sdk-javascript-1.18.17.tgz", "resolved": "http://npmprivate.quantgroups.com/sa-sdk-javascript/-/sa-sdk-javascript-1.18.18.tgz",
"integrity": "sha1-mLW7PyfL2jmwcCTb3G/Bes6H0n8=" "integrity": "sha1-gSIkQZUaeOEO+4GRBNB6aCn9YGs="
}, },
"safe-buffer": { "safe-buffer": {
"version": "5.2.1", "version": "5.2.1",
...@@ -23440,9 +23440,9 @@ ...@@ -23440,9 +23440,9 @@
} }
}, },
"url-toolkit": { "url-toolkit": {
"version": "2.2.2", "version": "2.2.3",
"resolved": "http://npmprivate.quantgroups.com/url-toolkit/-/url-toolkit-2.2.2.tgz", "resolved": "http://npmprivate.quantgroups.com/url-toolkit/-/url-toolkit-2.2.3.tgz",
"integrity": "sha512-l25w6Sy+Iy3/IbogunxhWwljPaDnqpiKvrQRoLBm6DfISco7NyRIS7Zf6+Oxhy1T8kHxWdwLND7ZZba6NjXMug==" "integrity": "sha512-Da75SQoxsZ+2wXS56CZBrj2nukQ4nlGUZUP/dqUBG5E1su5GKThgT94Q00x81eVII7AyS1Pn+CtTTZ4Z0pLUtQ=="
}, },
"urllib": { "urllib": {
"version": "2.37.1", "version": "2.37.1",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment