@ly-js/ui
Version:
`@ly-js/ui` 是基于`vue3`常用库,会在`@ly-js/element`、`@ly-js/vant`中引入
84 lines (79 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var utils = require('@ly-js/utils');
let baseUrl = "";
const getFullUrl = (url) => {
if (!url) {
return "";
}
return utils.isFullUrl(url) ? url : `${baseUrl}${url}`;
};
const setBaseUrl = (url) => {
baseUrl = url;
};
const getBaseUrl = () => {
return baseUrl;
};
const defaultformatSelectOptions = {
value: "value",
label: "label"
};
const setFormatSelectOptions = ({
value = "value",
label = "label"
} = {}) => {
defaultformatSelectOptions.label = label;
defaultformatSelectOptions.value = value;
};
const formatSelect = (val, list, options) => {
if (val === null || utils.isUndefined(val)) {
return "";
}
if (!utils.isArray(list)) {
return "";
}
let value = defaultformatSelectOptions.value;
let label = defaultformatSelectOptions.label;
if (utils.isString(options)) {
label = options;
} else if (utils.isObject(options)) {
label = options.label;
value = options.value;
}
const item = list.find((item2) => item2[value].toString() === val.toString());
return item ? item[label] : val;
};
const common = {
data() {
return {
$baseUrl: baseUrl
};
},
methods: {
$fullUrl(url) {
return getFullUrl(url);
},
$formatter(value, list, options = defaultformatSelectOptions.label) {
return formatSelect(value, list, options);
},
$go(url, replace = false) {
if (!replace) {
this.$router.push(url);
} else {
this.$router.replace(url);
}
},
$open(url, target = "_blank") {
window.open(url, target);
},
$back(n = 1) {
this.$router.go(n);
}
}
};
exports["default"] = common;
exports.formatSelect = formatSelect;
exports.getBaseUrl = getBaseUrl;
exports.getFullUrl = getFullUrl;
exports.setBaseUrl = setBaseUrl;
exports.setFormatSelectOptions = setFormatSelectOptions;