Commit 427ef7f6 authored by yiruiwen's avatar yiruiwen

Merge branch 'dev'

parents a8e8f5ba ec08ebf3
......@@ -9,6 +9,10 @@
// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明):
// import httpInterceptor from '@/common/http.interceptor.js'
// Vue.use(httpInterceptor, app)
// process.env.VUE_APP_PLATFORM 为通过js判断平台名称的方法,结果分别如下:
/**
* h5,app-plus(nvue下也为app-plus),mp-weixin,mp-alipay......
*/
},
}
</script>
......
import Vue from 'vue'
import App from './App'
import Vue from 'vue';
import App from './App';
Vue.config.productionTip = false
Vue.config.productionTip = false;
App.mpType = 'app'
App.mpType = 'app';
// 此处为演示Vue.prototype使用,非uView的功能部分
Vue.prototype.vuePrototype = '枣红'
Vue.prototype.vuePrototype = '枣红';
// 引入全局uView
import uView from 'uview-ui'
Vue.use(uView)
import uView from 'uview-ui';
Vue.use(uView);
// 此处为演示vuex使用,非uView的功能部分
import store from '@/store'
import store from '@/store';
// 引入uView提供的对vuex的简写法文件
let vuexStore = require('@/store/$u.mixin.js')
Vue.mixin(vuexStore)
let vuexStore = require('@/store/$u.mixin.js');
Vue.mixin(vuexStore);
// 引入uView对小程序分享的mixin封装
let mpShare = require('uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare)
Vue.mixin(mpShare);
// i18n部分的配置
// 引入语言包,注意路径
......@@ -29,10 +29,10 @@ import Chinese from '@/common/locales/zh.js';
import English from '@/common/locales/en.js';
// VueI18n
import VueI18n from '@/common/vue-i18n.min.js'
import VueI18n from '@/common/vue-i18n.min.js';
// VueI18n
Vue.use(VueI18n)
Vue.use(VueI18n);
const i18n = new VueI18n({
// 默认语言
......@@ -42,23 +42,23 @@ const i18n = new VueI18n({
'zh': Chinese,
'en': English,
}
})
});
// 由于微信小程序的运行机制问题,需声明如下一行,H5和APP非必填
Vue.prototype._i18n = i18n
Vue.prototype._i18n = i18n;
const app = new Vue({
i18n,
store,
...App
})
});
// http拦截器,将此部分放在new Vue()和app.$mount()之间,才能App.vue中正常使用
import httpInterceptor from '@/common/http.interceptor.js'
Vue.use(httpInterceptor, app)
import httpInterceptor from '@/common/http.interceptor.js';
Vue.use(httpInterceptor, app);
// http接口API抽离,免于写url或者一些固定的参数
import httpApi from '@/common/http.api.js'
Vue.use(httpApi, app)
import httpApi from '@/common/http.api.js';
Vue.use(httpApi, app);
app.$mount()
app.$mount();
......@@ -2,7 +2,7 @@
"name" : "uView",
"appid" : "__UNI__60F4B81",
"description" : "多平台快速开发的UI框架",
"versionName" : "1.7.8",
"versionName" : "1.7.9",
"versionCode" : "100",
"transformPx" : false,
"app-plus" : {
......
......@@ -53,7 +53,7 @@
export default {
data() {
return {
action: 'http://www.tp5.com',
action: 'http://127.0.0.1:7001/upload',
// 预置上传列表
fileList: [],
// fileList: [{
......
......@@ -3,7 +3,7 @@
<view class="u-demo-wrap">
<view class="u-demo-title">演示效果</view>
<view class="u-demo-area">
<view class="u-no-demo-here">时间戳为{{timestamp}}</view>
<view class="u-no-demo-here">输入时间{{timestamp}}</view>
<view class="u-demo-result-line">
{{result}}
</view>
......@@ -28,7 +28,7 @@
export default {
data() {
return {
timestamp: '1582711721',
timestamp: '2020-11-02T02:59:24.732Z',
result: null
}
},
......
......@@ -262,6 +262,7 @@ export default {
// 如果是与屏幕之间不留空隙,应该设置左右边距为0
margin-left: 0 !important;
margin-right: 0 !important;
width: 100%;
}
&--border:after {
......
......@@ -16,7 +16,7 @@
* @property {String Number} z-index z-index 层级(默认1070)
* @property {Object} custom-style 自定义样式对象,见上方说明
* @property {String Number} duration 动画时长,单位毫秒(默认300)
* @property {Boolean} zoom 是否使用scale对这招进行缩放(默认true)
* @property {Boolean} zoom 是否使用scale对遮罩进行缩放(默认true)
* @property {Boolean} mask-click-able 遮罩是否可点击,为false时点击不会发送click事件(默认true)
* @event {Function} click mask-click-able为true时,点击遮罩发送此事件
* @example <u-mask :show="show" @click="show = false"></u-mask>
......
......@@ -246,7 +246,9 @@ export default {
limitType:{
type: Array,
default() {
return ['png', 'jpg', 'jpeg', 'webp', 'gif'];
// 支付宝小程序真机选择图片的后缀为"image"
// https://opendocs.alipay.com/mini/api/media-image
return ['png', 'jpg', 'jpeg', 'webp', 'gif', 'image'];
}
},
// 在各个回调事件中的最后一个参数返回,用于区别是哪一个组件的事件
......
......@@ -82,6 +82,7 @@ const $u = {
date: timeFormat, // 另名date
timeFrom,
colorGradient: colorGradient.colorGradient,
colorToRgba: colorGradient.colorToRgba,
guid,
color,
sys,
......@@ -112,6 +113,9 @@ const $u = {
throttle,
}
// $u挂载到uni对象上
uni.$u = $u
const install = Vue => {
Vue.mixin(mixin)
if (Vue.prototype.openShare) {
......
// 此版本发布于2020-10-31
let version = '1.7.8';
// 此版本发布于2020-11-10
let version = '1.7.9';
export default {
v: version,
......
......@@ -93,8 +93,42 @@ function rgbToHex(rgb) {
}
}
/**
* JS颜色十六进制转换为rgb或rgba,返回的格式为 rgba(255,255,255,0.5)字符串
* sHex为传入的十六进制的色值
* alpha为rgba的透明度
*/
function colorToRgba(color, alpha = 0.3) {
color = rgbToHex(color)
// 十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
/* 16进制颜色转为RGB格式 */
let sColor = color.toLowerCase()
if (sColor && reg.test(sColor)) {
if (sColor.length === 4) {
var sColorNew = '#'
for (let i = 1; i < 4; i += 1) {
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
}
sColor = sColorNew
}
// 处理六位的颜色值
var sColorChange = []
for (let i = 1; i < 7; i += 2) {
sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)))
}
// return sColorChange.join(',')
return 'rgba(' + sColorChange.join(',') + ',' + alpha + ')'
}
else {
return sColor
}
}
export default {
colorGradient,
hexToRgb,
rgbToHex
rgbToHex,
colorToRgba
}
\ No newline at end of file
import queryParams from '../../libs/function/queryParams.js';
/**
* 路由跳转
* 注意:本方法没有对跳转的回调函数进行封装
* 路由跳转方法,该方法相对于直接使用uni.xxx的好处是使用更加简单快捷
* 并且带有路由拦截功能
*/
function route(options = {}, params = false) {
let config = {
class Router {
// 原始属性定义
config = {
type: 'navigateTo',
url: '',
delta: 1, // navigateBack页面后退时,回退的层数
params: {}, // 传递的参数
animationType: 'pop-in', // 窗口动画,只在APP有效
animationDuration: 300, // 窗口动画持续时间,单位毫秒,只在APP有效
};
config = Object.assign(config, options);
// 如果url没有"/"开头,添加上,因为uni的路由跳转需要"/"开头
if (config.url[0] != '/') config.url = '/' + config.url;
// 判断是否有传递显式的参数,Object.keys转为数组并判断长度,switchTab类型时不能携带参数
if (Object.keys(config.params).length && config.type != 'switchTab') {
// 判断用户传递的url中,是否带有参数
intercept: false, // 是否需要拦截
}
constructor() {
// 因为route方法是需要对外赋值给另外的对象使用,同时route内部有使用this,会导致route失去上下文
// 这里在构造函数中进行this绑定
this.route = this.route.bind(this)
}
// 判断url前面是否有"/",如果没有则加上,否则无法跳转
addRootPath(url) {
return String(url).indexOf('/') >= 0 ? url : `/${url}`
}
// 整合路由参数
mixinParam(url, params) {
// 使用正则匹配,主要依据是判断是否有"/","?","="等,如“/page/index/index?name=mary"
// 如果有url中有get参数,转换后无需带上"?"
let query = '';
if (/.*\/.*\?.*=.*/.test(config.url)) {
let query = ''
if (/.*\/.*\?.*=.*/.test(url)) {
// object对象转为get类型的参数
query = queryParams(config.params, false);
query = uni.$u.queryParams(params, false);
// 因为已有get参数,所以后面拼接的参数需要带上"&"隔开
config.url += "&" + query;
return url += "&" + query
} else {
query = queryParams(config.params);
config.url += query;
// 直接拼接参数,因为此处url中没有后面的query参数,也就没有"?/&"之类的符号
query = uni.$u.queryParams(params);
return url += query
}
}
// 简写形式,把url和参数拼接起来
if (typeof options === 'string' && typeof params == 'object') {
let query = '';
if (/.*\/.*\?.*=.*/.test(options)) {
// object对象转为get类型的参数
query = queryParams(params, false);
// 因为已有get参数,所以后面拼接的参数需要带上"&"隔开
options += "&" + query;
// 对外的方法名称
async route(options = {}, params = {}) {
// 合并用户的配置和内部的默认配置
let mergeConfig = {}
if (typeof options === 'string') {
// 如果options为字符串,则为route(url, params)的形式
mergeConfig.url = this.mixinParam(options, params)
mergeConfig.type = 'navigateTo'
} else {
query = queryParams(params);
options += query;
mergeConfig = uni.$u.deepClone(options, this.config)
// 否则正常使用mergeConfig中的url和params进行拼接
mergeConfig.url = this.mixinParam(options.url, options.params)
}
if(params.intercept) {
this.config.intercept = params.intercept
}
// params参数也带给拦截器
mergeConfig.params = params
// 合并内外部参数
mergeConfig = uni.$u.deepMerge(this.config, mergeConfig)
// 判断用户是否定义了拦截器
if (typeof uni.$u.routeIntercept === 'function') {
// 定一个promise,根据用户执行resolve(true)或者resolve(false)来决定是否进行路由跳转
const isNext = await new Promise((resolve, reject) => {
uni.$u.routeIntercept(mergeConfig, resolve)
})
// 如果isNext为true,则执行路由跳转
isNext && this.openPage(mergeConfig)
} else {
this.openPage(mergeConfig)
}
}
// 判断是否一个字符串,如果是,直接跳转(简写法)
// 如果是中情形,默认第二个参数为对象形式的参数
if (typeof options === 'string') {
if (options[0] != '/') options = '/' + options;
return uni.navigateTo({
url: options
});
}
// navigateTo类型的跳转
if (config.type == 'navigateTo' || config.type == 'to') {
return uni.navigateTo({
url: config.url,
animationType: config.animationType,
animationDuration: config.animationDuration,
});
}
if (config.type == 'redirectTo' || config.type == 'redirect') {
return uni.redirectTo({
url: config.url,
});
}
if (config.type == 'switchTab' || config.type == 'tab') {
return uni.switchTab({
url: config.url,
});
}
if (config.type == 'reLaunch') {
return uni.reLaunch({
url: config.url
});
}
if (config.type == 'navigateBack' || config.type == 'back') {
return uni.navigateBack({
delta: parseInt(config.delta ? config.delta : this.delta)
});
// 执行路由跳转
openPage(config) {
// 解构参数
const {
url,
type,
delta,
animationType,
animationDuration
} = config
if (config.type == 'navigateTo' || config.type == 'to') {
uni.navigateTo({
url,
animationType,
animationDuration
});
}
if (config.type == 'redirectTo' || config.type == 'redirect') {
uni.redirectTo({
url
});
}
if (config.type == 'switchTab' || config.type == 'tab') {
uni.switchTab({
url
});
}
if (config.type == 'reLaunch' || config.type == 'launch') {
uni.reLaunch({
url
});
}
if (config.type == 'navigateBack' || config.type == 'back') {
uni.navigateBack({
delta
});
}
}
}
export default route;
export default (new Router()).route
\ No newline at end of file
......@@ -21,15 +21,14 @@ if (!String.prototype.padStart) {
}
}
function timeFormat(timestamp = null, fmt = 'yyyy-mm-dd') {
// 其他更多是格式化有如下:
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
timestamp = parseInt(timestamp);
// 其他更多是格式化有如下:
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') {
// 如果为null,则格式化当前时间
if (!timestamp) timestamp = Number(new Date());
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
if (timestamp.toString().length == 10) timestamp *= 1000;
let date = new Date(timestamp);
if (!dateTime) dateTime = Number(new Date());
// 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式
if (dateTime.toString().length == 10) dateTime *= 1000;
let date = new Date(Number(dateTime));
let ret;
let opt = {
"y+": date.getFullYear().toString(), // 年
......
......@@ -6,13 +6,14 @@ import timeFormat from '../../libs/function/timeFormat.js';
* @param String | Boolean format 如果为时间格式字符串,超出一定时间范围,返回固定的时间格式;
* 如果为布尔值false,无论什么时间,都返回多久以前的格式
*/
function timeFrom(timestamp = null, format = 'yyyy-mm-dd') {
if (timestamp == null) timestamp = Number(new Date());
timestamp = parseInt(timestamp);
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
if (timestamp.toString().length == 10) timestamp *= 1000;
var timer = (new Date()).getTime() - timestamp;
timer = parseInt(timer / 1000);
function timeFrom(dateTime = null, format = 'yyyy-mm-dd') {
// 如果为null,则格式化当前时间
if (!dateTime) dateTime = Number(new Date());
// 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式
if (dateTime.toString().length == 10) dateTime *= 1000;
let timestamp = + new Date(Number(dateTime));
let timer = (Number(new Date()) - timestamp) / 1000;
// 如果小于5分钟,则返回"刚刚",其他以此类推
let tips = '';
switch (true) {
......
{
"name": "uview-ui",
"version": "1.7.8",
"version": "1.7.9",
"description": "uView UI,是uni-app生态优秀的UI框架,全面的组件和便捷的工具会让您信手拈来,如鱼得水",
"main": "index.js",
"keywords": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment