1.0.6 • Published 8 months ago
extsoul v1.0.6
说明
需要修改env的环境变量与theme的环境变量,所有变量、方法、样式均为ext-开头,不会影响到自有方法以及样式
js方法均可以使用this的方式获取,如果当前环境中不能使用this可使用uni来代替this
开始
安装方式
npm i extsoul
在main.js中引入extsoul
import extsoul from "extsoul";
Vue.use(extsoul);
在uni.scss中引入全局样式
@import 'extsoul/css/theme.scss';
内容简介
js方法
更新app包括热更新
/**
* @param { object } env 传入env对象,包含当前版本号 versionName 与热更新版本号 versionCode
* @param { object } res 包含以下属性
* @param { string } versionName 整包更新版本号
* @param { string } versionCode 热更新更新版本号
* @param { string } appUrl 整包更新地址
* @param { string } hotURL 热更新地址
*/
this.$ext.upapp(env,res);
获取当前项目配置
其中包含当前api地址、线上图片地址
/**
* @param { object } res 包含以下属性,更新依赖env文件中的版本号与热更新版本号请先创建env.js
* @param { string } versionName 整包更新版本号
* @param { string } versionCode 热更新更新版本号
*/
this.$ext.env
时间格式化
/**
* @param {string || dateTime} dateTime 可传入时间戳或日期
* @param {string} fmt 欲格式化样式 yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
*/
this.$ext.timeFormat(dateTime,fmt)
列表转树
/**
* 列表转树
* @param {Array} data 数据源
* @param {String||Number} id id字段 默认 'id'
* @param {String||Number} parentId 父节点字段 默认 'parentId'
* @param {Array} children 孩子节点字段 默认 'children'
*/
this.$ext.handleTree(data, id, parentId, children)
节流
/**
* @param {Function} func 要执行的回调函数
* @param {Number} wait 延时的时间
* @param {Boolean} immediate 是否立即执行
* @return null
*/
this.$ext.throttle(function, 500)
去除空格
/**
* 该方法可以去除空格,分别可以去除所有空格,两端空格,左边空格,右边空格,默认为去除两端空格
* @param str {string} str 字符串
* @param pos {string} pos 去除那些位置的空格,可选为:both-默认值,去除两端空格,left-去除左边空格,right-去除右边空格 all 去除全部
*/
this.$ext.trim(str, pos = 'both')
规则校验
// 验证电子邮箱格式
this.$ext.test.email(value)
// 验证手机格式
this.$ext.test.mobile(value)
// 验证URL格式
this.$ext.test.url(value)
// 验证日期格式
this.$ext.test.date(value)
// 验证ISO类型的日期格式
this.$ext.test.dateISO(value)
// 验证十进制数字
this.$ext.test.number(value)
// 验证整数
this.$ext.test.digits(value)
// 验证身份证号码
this.$ext.test.idCard(value)
// 是否车牌号
this.$ext.test.carNo(value)
// 验证一个值范围[min, max]
this.$ext.test.range(value, param)
// 验证一个长度范围[min, max]
this.$ext.test.rangeLength(value, param)
// 是否固定电话
this.$ext.test.landline(value)
// 判断是否为空
this.$ext.test.empty(value)
// 是否json字符串
this.$ext.test.jsonString(value)
// 是否数组
this.$ext.test.array(value)
// 是否对象
this.$ext.test.object(value)
// 是否短信验证码
this.$ext.test.code(value, len = 6)
css公共变量公共样式以及公共样式
样式已经进行全局注册,无需引入可直接在css中进行调用,如涉及到某个文字图片仅需要进行居中对齐颜色等操作无需创建class直接调用即可
全局变量
$ext-IMG_URL // css中图片网络路径前缀
$ext-main-color // 主要颜色
$ext-content-color // 文本颜色
$ext-tip-color // 次要颜色
$ext-light-color // 占位颜色
公共样式
/* 文字左对齐 */
.ext-text-left
/* 文字居中对齐 */
.ext-text-center
/* 文字右对齐 */
.ext-text-right
// 主要颜色
.ext-main-color
// 文本颜色
.ext-content-color
// 次要颜色
.ext-tip-color
// 占位颜色
.ext-light-color