123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <template>
- <div>
- <div @click="init()">
- <img src="./assets/image/testPc.jpg" style="width:100%;height:auto" v-if="type=='PC'"/>
- <div class="app" v-else :style="{width:width}">
- <img src="./assets/image/test.jpg" :style="{width:width,height:'auto'}"/>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { openTryoutSku, contactAdminToUseApp } from 'dingtalk-design-libs';
- export default {
- data() {
- return {
- corpId: '',
- token: '',
- type: 'PC',
- width:'',
- };
- },
- created() {
- this.width=document.body.clientWidth+'px'
- },
- mounted() {
- var url = window.location.href;
- var data = this.GetRequest(url);
- console.log(data);
- this.corpId = data.corpId;
- this.token = data.purchaseToken;
- this.type = data.appEntityType;
- if (this.corpId) {
- this.init();
- }
- },
- methods: {
- init() {
- // 开发者自行判断调用这个方法的时机
- openTryoutSku({
- // corpId可以从应用首页的url上获取到
- corpId: this.corpId,
- // 应用的appId
- appId: 55493,
- // 从应用首页的url上获取到,url上参数名为 purchaseToken。
- // purchaseToken如何配置参照下文”配置入口地址“章节。
- token: this.token,
- miniAppId: this.token == 'APP' ? 55493 : '' // 如果是三方小程序应用,需要设置一下自身的miniAppId。H5微应用可以不设置这个参数
- }).then(res => {
- const {
- // action的值为:
- // 'ok',用户执行了开通动作,或将自己加入了已开通的应用的可见范围内
- // 'cancel', 用户点击了取消按钮
- // 'unknown',用户点击空白区域关闭了弹窗,此时可以跟cancel采取同样的处理逻辑
- action,
- // 开通了应用的组织的corpId。因为个人开通可能会用钉钉的隐藏组织,所以开通应用的组织的corpId以这里返回的为准。
- corpId
- } = res;
- console.log(action, corpId);
- if (action === 'ok') {
- this.$dd.biz.util.openLink({
- url: 'http://www.dingtalk.com', //要打开链接的地址
- onSuccess: function(result) {
- this.$dd.biz.navigation.close();
- },
- onFail: function(err) {}
- });
- }
- // action不是ok的情况下,可以不采取任何动作
- })
- .catch(() => {
- // 钉钉侧出现了技术异常,比如打开弹窗失败等,出现概率非常低
- });
- },
- GetRequest(urlStr) {
- if (typeof urlStr == 'undefined') {
- var url = decodeURI(location.search); //获取url中"?"符后的字符串
- } else {
- var url = '?' + urlStr.split('?')[1];
- }
- var theRequest = new Object();
- var strs;
- if (url.indexOf('?') != -1) {
- var str = url.substr(1);
- strs = str.split('&');
- for (var i = 0; i < strs.length; i++) {
- theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
- }
- }
- return theRequest;
- }
- }
- };
- </script>
- <style scoped="scoped">
- .app{
- margin: 0 auto;
- height: auto;
- padding: 0;
- }
- .app img{
- /* width: 375px; */
- }
-
- </style>
|