mirror of
https://github.com/sahadev/vue-component-creater-ui.git
synced 2025-06-06 13:04:05 +08:00
56 lines
1.1 KiB
JavaScript
56 lines
1.1 KiB
JavaScript
import qs from 'query-string';
|
|
import deepmerge from 'deepmerge';
|
|
|
|
const DEFAULT_PARAMS = {
|
|
pkgs: ['https://static.imonkey.xueersi.com/vue-code-creater/resource/vue.js', 'https://static.imonkey.xueersi.com/vue-code-creater/resource/element-ui/index.js'],
|
|
css: ['https://static.imonkey.xueersi.com/vue-code-creater/resource/element-ui/index.css'],
|
|
};
|
|
|
|
let params = DEFAULT_PARAMS;
|
|
|
|
function getArr(str) {
|
|
if (Array.isArray(str)) {
|
|
return str;
|
|
}
|
|
if (typeof str === 'string') {
|
|
return str.split(',');
|
|
}
|
|
return [];
|
|
}
|
|
|
|
export function clear() {
|
|
params = DEFAULT_PARAMS;
|
|
}
|
|
|
|
export function parse(str) {
|
|
try {
|
|
merge(JSON.parse(str));
|
|
} catch (e) {
|
|
console.error('error', e.message);
|
|
}
|
|
}
|
|
|
|
export function queryParse(str) {
|
|
const query = qs.parse(str);
|
|
const pkgs = getArr(query.pkg);
|
|
const css = getArr(query.css);
|
|
const options = { pkgs, css };
|
|
|
|
if (query.cdn) {
|
|
options.cdn = query.cdn;
|
|
}
|
|
if (query.vue) {
|
|
options.vue = query.vue;
|
|
}
|
|
|
|
merge(options);
|
|
}
|
|
|
|
export function get() {
|
|
return deepmerge(DEFAULT_PARAMS, params);
|
|
}
|
|
|
|
export function merge(opts) {
|
|
params = deepmerge(params, opts);
|
|
}
|