UNPKG

@ly-js/ui

Version:

`@ly-js/ui` 是基于`vue3`常用库,会在`@ly-js/element`、`@ly-js/vant`中引入

75 lines (72 loc) 1.74 kB
import { isFullUrl, isUndefined, isArray, isString, isObject } from '@ly-js/utils'; let baseUrl = ""; const getFullUrl = (url) => { if (!url) { return ""; } return 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 || isUndefined(val)) { return ""; } if (!isArray(list)) { return ""; } let value = defaultformatSelectOptions.value; let label = defaultformatSelectOptions.label; if (isString(options)) { label = options; } else if (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); } } }; export { common as default, formatSelect, getBaseUrl, getFullUrl, setBaseUrl, setFormatSelectOptions };