Browse Source

plugin sdk 修改

master
wally 4 years ago
parent
commit
39afb92fb4
  1. 162
      package-lock.json
  2. 140
      public/sdk.js
  3. 9
      src/App.vue

162
package-lock.json

@ -1808,16 +1808,6 @@
"integrity": "sha1-/q7SVZc9LndVW4PbwIhRpsY1IPo=",
"dev": true
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-4.3.0.tgz?cache=0&sync_timestamp=1611327117754&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-4.3.0.tgz",
"integrity": "sha1-7dgDYornHATIWuegkG7a00tkiTc=",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"cacache": {
"version": "13.0.1",
"resolved": "https://registry.npm.taobao.org/cacache/download/cacache-13.0.1.tgz?cache=0&sync_timestamp=1594427999421&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcacache%2Fdownload%2Fcacache-13.0.1.tgz",
@ -1850,34 +1840,6 @@
"integrity": "sha1-48mzFWnhBoEd8kL3FXJaH0xJQyA=",
"dev": true
},
"chalk": {
"version": "4.1.0",
"resolved": "https://registry.npm.taobao.org/chalk/download/chalk-4.1.0.tgz",
"integrity": "sha1-ThSHCmGNni7dl92DRf2dncMVZGo=",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npm.taobao.org/color-convert/download/color-convert-2.0.1.tgz",
"integrity": "sha1-ctOmjVmMm9s68q0ehPIdiWq9TeM=",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npm.taobao.org/color-name/download/color-name-1.1.4.tgz",
"integrity": "sha1-wqCah6y95pVD3m9j+jmVyCbFNqI=",
"dev": true,
"optional": true
},
"css-loader": {
"version": "3.6.0",
"resolved": "https://registry.npm.taobao.org/css-loader/download/css-loader-3.6.0.tgz?cache=0&sync_timestamp=1604507107408&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcss-loader%2Fdownload%2Fcss-loader-3.6.0.tgz",
@ -1931,13 +1893,6 @@
"universalify": "^0.1.0"
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/has-flag/download/has-flag-4.0.0.tgz",
"integrity": "sha1-lEdx/ZyByBJlxNaUGGDaBrtZR5s=",
"dev": true,
"optional": true
},
"icss-utils": {
"version": "4.1.1",
"resolved": "https://registry.npm.taobao.org/icss-utils/download/icss-utils-4.1.1.tgz?cache=0&sync_timestamp=1602527330977&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ficss-utils%2Fdownload%2Ficss-utils-4.1.1.tgz",
@ -2052,16 +2007,6 @@
"minipass": "^3.1.1"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-7.2.0.tgz?cache=0&sync_timestamp=1611394043517&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-7.2.0.tgz",
"integrity": "sha1-G33NyzK4E4gBs+R4umpRyqiWSNo=",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"terser-webpack-plugin": {
"version": "2.3.8",
"resolved": "https://registry.npm.taobao.org/terser-webpack-plugin/download/terser-webpack-plugin-2.3.8.tgz?cache=0&sync_timestamp=1603881757308&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fterser-webpack-plugin%2Fdownload%2Fterser-webpack-plugin-2.3.8.tgz",
@ -2078,32 +2023,6 @@
"terser": "^4.6.12",
"webpack-sources": "^1.4.3"
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.1.2",
"resolved": "https://registry.npm.taobao.org/vue-loader/download/vue-loader-16.1.2.tgz?cache=0&sync_timestamp=1608188050165&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-loader%2Fdownload%2Fvue-loader-16.1.2.tgz",
"integrity": "sha1-XAO2xQ0qX5g8fOuhXFDXjKKymPQ=",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"loader-utils": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/loader-utils/download/loader-utils-2.0.0.tgz",
"integrity": "sha1-5MrOW4FtQloWa18JfhDNErNgZLA=",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
}
}
}
}
},
@ -12677,6 +12596,87 @@
}
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.1.2",
"resolved": "https://registry.npm.taobao.org/vue-loader/download/vue-loader-16.1.2.tgz",
"integrity": "sha1-XAO2xQ0qX5g8fOuhXFDXjKKymPQ=",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-4.3.0.tgz?cache=0&sync_timestamp=1611327117754&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-4.3.0.tgz",
"integrity": "sha1-7dgDYornHATIWuegkG7a00tkiTc=",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.0",
"resolved": "https://registry.npm.taobao.org/chalk/download/chalk-4.1.0.tgz?cache=0&sync_timestamp=1591686984650&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fchalk%2Fdownload%2Fchalk-4.1.0.tgz",
"integrity": "sha1-ThSHCmGNni7dl92DRf2dncMVZGo=",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npm.taobao.org/color-convert/download/color-convert-2.0.1.tgz",
"integrity": "sha1-ctOmjVmMm9s68q0ehPIdiWq9TeM=",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npm.taobao.org/color-name/download/color-name-1.1.4.tgz",
"integrity": "sha1-wqCah6y95pVD3m9j+jmVyCbFNqI=",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/has-flag/download/has-flag-4.0.0.tgz",
"integrity": "sha1-lEdx/ZyByBJlxNaUGGDaBrtZR5s=",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/loader-utils/download/loader-utils-2.0.0.tgz",
"integrity": "sha1-5MrOW4FtQloWa18JfhDNErNgZLA=",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-7.2.0.tgz?cache=0&sync_timestamp=1611394043517&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-7.2.0.tgz",
"integrity": "sha1-G33NyzK4E4gBs+R4umpRyqiWSNo=",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-quill-editor": {
"version": "3.0.6",
"resolved": "https://registry.npm.taobao.org/vue-quill-editor/download/vue-quill-editor-3.0.6.tgz",

140
public/sdk.js

@ -1,70 +1,82 @@
;(function(window) {
var _instance = null;
window.TallPlugin = function(config) {
this.config = config;
this.props = null;
}
// 初始化并保证是单例
TallPlugin.init = function (config) {
if (!_instance) {
_instance = new TallPlugin(config);
}
return _instance;
}
(function(window) {
var _instance = null;
window.TallPlugin = function(config) {
this.config = config;
this.props = null;
};
TallPlugin.prototype.created = function (callback) {
var _this = this;
window.postMessage('created');
window.addEventListener('message', function ({ data, origin }) {
try {
var target = JSON.parse(data);
if (target.success) {
_this.props = JSON.parse(data);
callback && typeof callback === 'function' && callback.call(_this, _this.props);
} else {
_this.props = null;
}
} catch (e) {
_this.props = null;
}
}, false);
// DOM加载完成
window.addEventListener('DOMContentLoaded', this.mounted, false);
// window onload
window.addEventListener('load', this.loaded, false);
// destroy
window.addEventListener('unload', this.destroy, false);
// error
window.addEventListener('error', this.error, false);
return this;
// 初始化并保证是单例
TallPlugin.init = function(config) {
if (!_instance) {
_instance = new TallPlugin(config);
}
return _instance;
};
TallPlugin.prototype.mounted = function(callback) {
console.log('mounted');
window.postMessage('mounted');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
function postMsg(message) {
let origin = '*';
window.postMessage(message, origin);
}
TallPlugin.prototype.loaded = function(callback) {
console.log('loaded');
window.postMessage('loaded');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
TallPlugin.prototype.created = function(callback) {
console.log('created begin');
var _this = this;
postMsg('created');
window.addEventListener(
'message',
function({ data, origin }) {
console.log('on created message, data, origin: ', data, origin);
try {
var target = JSON.parse(data);
if (target.success) {
_this.props = JSON.parse(data);
callback && typeof callback === 'function' && callback.call(_this, _this.props);
}
// else {
// _this.props = null;
// }
} catch (e) {
_this.props = null;
}
},
false,
);
// DOM加载完成
window.addEventListener('DOMContentLoaded', this.mounted, false);
// window onload
window.addEventListener('load', this.loaded, false);
// destroy
window.addEventListener('unload', this.destroy, false);
// error
window.addEventListener('error', this.error, false);
return this;
};
TallPlugin.prototype.destroy = function(callback) {
console.log('destroy');
window.postMessage('destroy');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
TallPlugin.prototype.mounted = function(callback) {
console.log('mounted');
postMsg('mounted');
callback && typeof callback === 'function' && callback.call(this);
return this;
};
TallPlugin.prototype.error = function(callback) {
console.log('error');
window.postMessage('error');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
})(window)
TallPlugin.prototype.loaded = function(callback) {
console.log('loaded');
postMsg('loaded');
callback && typeof callback === 'function' && callback.call(this);
return this;
};
TallPlugin.prototype.destroy = function(callback) {
console.log('destroy');
postMsg('destroy');
callback && typeof callback === 'function' && callback.call(this);
return this;
};
TallPlugin.prototype.error = function(callback) {
console.log('error');
postMsg('error');
callback && typeof callback === 'function' && callback.call(this);
return this;
};
})(window);

9
src/App.vue

@ -1,3 +1,10 @@
<!--
* @Author: wally
* @email: 18603454788@163.com
* @Date: 2021-02-19 17:44:32
* @LastEditors: wally
* @LastEditTime: 2021-02-20 09:15:41
-->
<template>
<a-config-provider :locale="zh_CN">
<div class="d-flex flex-row flex-nowrap" id="app">
@ -26,7 +33,7 @@ export default {
const params = { userId };
this.getUserId(params);
window.plugin = TallPlugin.init();
window.plugin = window.TallPlugin.init();
// created created便
// created created
window.plugin.created(function(props) {

Loading…
Cancel
Save