From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 11:46:57 +0800 Subject: [PATCH] 项目初始化 --- uni_modules/uview-ui/libs/mixin/style.js | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 228 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/libs/mixin/style.js b/uni_modules/uview-ui/libs/mixin/style.js new file mode 100644 index 0000000..2660180 --- /dev/null +++ b/uni_modules/uview-ui/libs/mixin/style.js @@ -0,0 +1,228 @@ +export default { + props: { + // flex鎺掑垪鏂瑰紡 + flexDirection: { + type: String, + default: '' + }, + // flex-direction鐨勭畝鍐� + fd: { + type: String, + default: '' + }, + // 灞曠ず绫诲瀷 + display: { + type: String, + default: '' + }, + // display绠�鍐� + d: { + type: String, + default: '' + }, + // 涓昏酱鎺掑垪鏂瑰紡 + justifyContent: { + type: String, + default: '' + }, + // justifyContent鐨勭畝鍐� + jc: { + type: String, + default: '' + }, + // 绾佃酱鎺掑垪鏂瑰紡 + alignItems: { + type: String, + default: '' + }, + // align-items鐨勭畝鍐� + ai: { + type: String, + default: '' + }, + color: { + type: String, + default: '' + }, + // color绠�鍐� + c: { + type: String, + default: '' + }, + // 瀛椾綋澶у皬 + fontSize: { + type: [String, Number], + default: 0 + }, + // font-size绠�鍐� + fs: { + type: [String, Number], + default: '' + }, + margin: { + type: [String, Number], + default: 0 + }, + // margin绠�鍐� + m: { + type: [String, Number], + default: 0 + }, + // margin-top + marginTop: { + type: [String, Number], + default: 0 + }, + // margin-top绠�鍐� + mt: { + type: [String, Number], + default: 0 + }, + // margin-right + marginRight: { + type: [String, Number], + default: 0 + }, + // margin-right绠�鍐� + mr: { + type: [String, Number], + default: 0 + }, + // margin-bottom + marginBottom: { + type: [String, Number], + default: 0 + }, + // margin-bottom绠�鍐� + mb: { + type: [String, Number], + default: 0 + }, + // margin-left + marginLeft: { + type: [String, Number], + default: 0 + }, + // margin-left绠�鍐� + ml: { + type: [String, Number], + default: 0 + }, + // padding-left + paddingLeft: { + type: [String, Number], + default: 0 + }, + // padding-left绠�鍐� + pl: { + type: [String, Number], + default: 0 + }, + // padding-top + paddingTop: { + type: [String, Number], + default: 0 + }, + // padding-top绠�鍐� + pt: { + type: [String, Number], + default: 0 + }, + // padding-right + paddingRight: { + type: [String, Number], + default: 0 + }, + // padding-right绠�鍐� + pr: { + type: [String, Number], + default: 0 + }, + // padding-bottom + paddingBottom: { + type: [String, Number], + default: 0 + }, + // padding-bottom绠�鍐� + pb: { + type: [String, Number], + default: 0 + }, + // border-radius + borderRadius: { + type: [String, Number], + default: 0 + }, + // border-radius绠�鍐� + radius: { + type: [String, Number], + default: 0 + }, + // transform + transform: { + type: String, + default: '' + }, + // 瀹氫綅 + position: { + type: String, + default: '' + }, + // position绠�鍐� + pos: { + type: String, + default: '' + }, + // 瀹藉害 + width: { + type: [String, Number], + default: null + }, + // width绠�鍐� + w: { + type: [String, Number], + default: null + }, + // 楂樺害 + height: { + type: [String, Number], + default: null + }, + // height绠�鍐� + h: { + type: [String, Number], + default: null + }, + top: { + type: [String, Number], + default: 0 + }, + right: { + type: [String, Number], + default: 0 + }, + bottom: { + type: [String, Number], + default: 0 + }, + left: { + type: [String, Number], + default: 0 + } + }, + computed: { + viewStyle() { + const style = {} + const addStyle = uni.$u.addStyle(this.width || this.w) && (style.width = addStyle(this.width || this.w))(this.height || this.h) && (style.height = addStyle(this.height || this.h))(this.margin || this.m) && (style.margin = addStyle(this.margin || this.m))(this.marginTop || this.mt) && (style.marginTop = addStyle(this.marginTop || this.mt))(this.marginRight || this.mr) && (style.marginRight = addStyle(this.marginRight || this.mr))(this.marginBottom || this.mb) && (style.marginBottom = addStyle(this.marginBottom || this.mb))(this.marginLeft || this.ml) && (style.marginLeft = addStyle(this.marginLeft || this.ml))(this.padding || this.p) && (style.padding = addStyle(this.padding || this.p))(this.paddingTop || this.pt) && (style.paddingTop = addStyle(this.paddingTop || this.pt))(this.paddingRight || this.pr) && (style.paddingRight = addStyle(this.paddingRight || this.pr))(this.paddingBottom || this.pb) && (style.paddingBottom = addStyle(this.paddingBottom || this.pb))(this.paddingLeft || this.pl) && (style.paddingLeft = addStyle(this.paddingLeft || this.pl))(this.color || this.c) && (style.color = this.color || this.c)(this.fontSize || this.fs) && (style.fontSize = this.fontSize || this.fs)(this.borderRadius || this.radius) && (style.borderRadius = this.borderRadius || this.radius)(this.position || this.pos) && (this.position = this.position || this.pos)(this.flexDirection || this.fd) && (this.flexDirection = this.flexDirection || this.fd)(this.justifyContent || jc) && (this.justifyContent = this.justifyContent || jc)(this.alignItems || ai) && (this.alignItems = this.alignItems || ai) + + return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle)) + } + }, + methods: { + // 鑾峰彇margin鎴栬�卲adding鐨勫崟浣嶏紝姣斿padding: 0 20杞负padding: 0 20px + getUnit(unit = '') { + // 鍙栧嚭涓ょ绌烘牸锛屽垎闅旀垚鏁扮粍锛屽啀瀵规暟缁勭殑姣忎釜鍏冪礌娣诲姞鍗曚綅锛屾渶鍚庡啀鍚堝苟鎴愬瓧绗︿覆 + return uni.$u.trim(unit).split(' ').map((item) => uni.$u.addUnit(item)).join(' ') + } + } +} -- Gitblit v1.9.3