uni-wot-ui-plus
Version:
🦄基于uni-ui的二次封装的uniapp组件库
283 lines (272 loc) • 7.61 kB
JavaScript
'use strict';
const process = require('node:process');
const vue = require('vue');
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
const n = Object.create(null);
if (e) {
for (const k in e) {
n[k] = e[k];
}
}
n.default = e;
return n;
}
const process__namespace = /*#__PURE__*/_interopNamespaceCompat(process);
function isObj(value) {
return Object.prototype.toString.call(value) === "[object Object]" || typeof value === "object";
}
function getType(target) {
const typeStr = Object.prototype.toString.call(target);
const match = typeStr.match(/\[object (\w+)\]/);
const type = match && match.length ? match[1].toLowerCase() : "";
return type;
}
const isDef = (value) => value !== void 0 && value !== null;
function camelCase(word) {
return word.replace(/-(\w)/g, (_, c) => c.toUpperCase());
}
function isFunction(value) {
return getType(value) === "function" || getType(value) === "asyncfunction";
}
function deepAssign(target, source) {
Object.keys(source).forEach((key) => {
const targetValue = target[key];
const newObjValue = source[key];
if (isObj(targetValue) && isObj(newObjValue)) {
deepAssign(targetValue, newObjValue);
} else {
target[key] = newObjValue;
}
});
return target;
}
const getPropByPath = (obj, path) => {
const keys = path.split(".");
try {
return keys.reduce((acc, key) => acc !== void 0 && acc !== null ? acc[key] : void 0, obj);
} catch (error) {
return void 0;
}
};
const zhCN = {
pleaseInput: "\u8BF7\u8F93\u5165",
pleaseSelect: "\u8BF7\u9009\u62E9",
calendar: {
placeholder: "\u8BF7\u9009\u62E9",
title: "\u9009\u62E9\u65E5\u671F",
day: "\u65E5",
week: "\u5468",
month: "\u6708",
confirm: "\u786E\u5B9A",
startTime: "\u5F00\u59CB\u65F6\u95F4",
endTime: "\u7ED3\u675F\u65F6\u95F4",
to: "\u81F3",
timeFormat: "YY\u5E74MM\u6708DD\u65E5 HH:mm:ss",
dateFormat: "YYYY\u5E74MM\u6708DD\u65E5",
weekFormat: (year, week) => `${year} \u7B2C ${week} \u5468`,
startWeek: "\u5F00\u59CB\u5468",
endWeek: "\u7ED3\u675F\u5468",
startMonth: "\u5F00\u59CB\u6708",
endMonth: "\u7ED3\u675F\u6708",
monthFormat: "YYYY\u5E74MM\u6708"
},
calendarView: {
startTime: "\u5F00\u59CB",
endTime: "\u7ED3\u675F",
weeks: {
sun: "\u65E5",
mon: "\u4E00",
tue: "\u4E8C",
wed: "\u4E09",
thu: "\u56DB",
fri: "\u4E94",
sat: "\u516D"
},
rangePrompt: (maxRange) => `\u9009\u62E9\u5929\u6570\u4E0D\u80FD\u8D85\u8FC7${maxRange}\u5929`,
rangePromptWeek: (maxRange) => `\u9009\u62E9\u5468\u6570\u4E0D\u80FD\u8D85\u8FC7${maxRange}\u5468`,
rangePromptMonth: (maxRange) => `\u9009\u62E9\u6708\u4EFD\u4E0D\u80FD\u8D85\u8FC7${maxRange}\u4E2A\u6708`,
monthTitle: "YYYY\u5E74M\u6708",
yearTitle: "YYYY\u5E74",
month: "M\u6708",
hour: (value) => `${value}\u65F6`,
minute: (value) => `${value}\u5206`,
second: (value) => `${value}\u79D2`
},
collapse: {
expand: "\u5C55\u5F00",
retract: "\u6536\u8D77"
},
colPicker: {
title: "\u8BF7\u9009\u62E9",
placeholder: "\u8BF7\u9009\u62E9",
select: "\u8BF7\u9009\u62E9"
},
datetimePicker: {
start: "\u5F00\u59CB\u65F6\u95F4",
end: "\u7ED3\u675F\u65F6\u95F4",
to: "\u81F3",
placeholder: "\u8BF7\u9009\u62E9",
confirm: "\u5B8C\u6210",
cancel: "\u53D6\u6D88"
},
loadmore: {
loading: "\u6B63\u5728\u52AA\u529B\u52A0\u8F7D\u4E2D...",
finished: "\u5DF2\u52A0\u8F7D\u5B8C\u6BD5",
error: "\u52A0\u8F7D\u5931\u8D25",
retry: "\u70B9\u51FB\u91CD\u8BD5"
},
messageBox: {
inputPlaceholder: "\u8BF7\u8F93\u5165",
confirm: "\u786E\u5B9A",
cancel: "\u53D6\u6D88",
inputNoValidate: "\u8F93\u5165\u7684\u6570\u636E\u4E0D\u5408\u6CD5"
},
numberKeyboard: {
confirm: "\u5B8C\u6210"
},
pagination: {
prev: "\u4E0A\u4E00\u9875",
next: "\u4E0B\u4E00\u9875",
page: (value) => `\u5F53\u524D\u9875\uFF1A${value}`,
total: (total) => `\u5F53\u524D\u6570\u636E\uFF1A${total}\u6761`,
size: (size) => `\u5206\u9875\u5927\u5C0F\uFF1A${size}`
},
picker: {
cancel: "\u53D6\u6D88",
done: "\u5B8C\u6210",
placeholder: "\u8BF7\u9009\u62E9"
},
imgCropper: {
confirm: "\u5B8C\u6210",
cancel: "\u53D6\u6D88"
},
search: {
search: "\u641C\u7D22",
cancel: "\u53D6\u6D88"
},
steps: {
wait: "\u672A\u5F00\u59CB",
finished: "\u5DF2\u5B8C\u6210",
process: "\u8FDB\u884C\u4E2D",
failed: "\u5931\u8D25"
},
tabs: {
all: "\u5168\u90E8"
},
upload: {
error: "\u4E0A\u4F20\u5931\u8D25"
},
input: {
placeholder: "\u8BF7\u8F93\u5165..."
},
selectPicker: {
title: "\u8BF7\u9009\u62E9",
placeholder: "\u8BF7\u9009\u62E9",
select: "\u8BF7\u9009\u62E9",
confirm: "\u786E\u8BA4",
filterPlaceholder: "\u641C\u7D22"
},
tag: {
placeholder: "\u8BF7\u8F93\u5165",
add: "\u65B0\u589E\u6807\u7B7E"
},
textarea: {
placeholder: "\u8BF7\u8F93\u5165..."
},
tableCol: {
indexLabel: "\u5E8F\u53F7"
},
signature: {
confirmText: "\u786E\u8BA4",
clearText: "\u6E05\u7A7A",
revokeText: "\u64A4\u9500",
restoreText: "\u6062\u590D"
}
};
const lang = vue.ref("zh-CN");
const messages = vue.reactive({
"zh-CN": zhCN
});
const Locale = {
messages() {
return messages[lang.value];
},
use(newLang, newMessage) {
lang.value = newLang;
if (newMessage) {
this.add({ [newLang]: newMessage });
}
},
add(newMessages = {}) {
deepAssign(messages, newMessages);
}
};
const useTranslate = (name) => {
const prefix = name ? camelCase(name) + "." : "";
const translate = (key, ...args) => {
const currentMessages = Locale.messages();
const message = getPropByPath(currentMessages, prefix + key);
return isFunction(message) ? message(...args) : isDef(message) ? message : `${prefix}${key}`;
};
return { translate };
};
function useForm() {
const handleSetFormItems = (formItems) => {
formItems = formItems.slice().sort((a, b) => {
if (a.sort < b.sort) return -1;
if (a.sort > b.sort) return 1;
return 0;
});
return formItems.filter((item) => {
return !item.isHide;
});
};
const handleInitForm = (formItems) => {
const form = {};
formItems?.forEach((item) => {
if (item.defaultValue || item.defaultValue === 0) {
form[item.field] = item.defaultValue;
} else {
form[item.field] = "";
}
});
return form;
};
const handleValidateForm = async (ckForm) => {
const result = await ckForm.handleValidateForm();
return result.valid;
};
const handleResetForm = (ckForm) => {
ckForm.handleResetForm();
};
return {
handleSetFormItems,
handleInitForm,
handleValidateForm,
handleResetForm
};
}
const processShim = process__namespace === void 0 ? {} : process__namespace;
const envShim = processShim.env || {};
envShim.UNI_PLATFORM;
function UpResolver() {
return {
type: "component",
resolve: (name) => {
if (/^(Up[A-Z]|up-[a-z])/.test(name)) {
const cName = name.slice(2).replace(/([a-z])/, "$1").toLowerCase();
const component = `uni-wot-ui-plus/components/${cName}/${cName}.vue`;
return {
name,
from: component,
// 移除样式文件的自动导入,使其完全可选
sideEffects: []
};
}
}
};
}
exports.UpResolver = UpResolver;
exports.useForm = useForm;
exports.useTranslate = useTranslate;