清空
This commit is contained in:
File diff suppressed because one or more lines are too long
-2
File diff suppressed because one or more lines are too long
@@ -1,542 +0,0 @@
|
||||
var CODE_SUCCESS = 200;
|
||||
var access_token = getCookie("access_token");
|
||||
var PostBase = {
|
||||
access_token: access_token,
|
||||
plat: "admin",
|
||||
version: "10000"
|
||||
};
|
||||
function logout() {
|
||||
var that = this;
|
||||
var r=confirm("是否确认安全退出?");
|
||||
if (r==true){
|
||||
axios.post('/admin/admin/logout', Object.assign({}, PostBase))
|
||||
.then(function (res) {
|
||||
if (res.data.code == 200) {
|
||||
window.location.href = "/qfadmin"
|
||||
} else {
|
||||
alert(res.data.message)
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
});
|
||||
}
|
||||
}
|
||||
//写cookies
|
||||
function setCookie(name, value) {
|
||||
var Days = 30;
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
|
||||
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
|
||||
}
|
||||
//读取cookies
|
||||
function getCookie(name) {
|
||||
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
|
||||
|
||||
if (arr = document.cookie.match(reg))
|
||||
|
||||
return unescape(arr[2]);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
//删除cookies
|
||||
function delCookie(name) {
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() - 1);
|
||||
var cval = getCookie(name);
|
||||
if (cval != null)
|
||||
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
|
||||
}
|
||||
|
||||
const isDebug = true;
|
||||
function echo(message, color = "#000", fontSize = "14") {
|
||||
if (isDebug) {
|
||||
console.log("%c " + message, "font-size:" + fontSize + "px;color:" + color + ";font-weight:bold;");
|
||||
}
|
||||
}
|
||||
|
||||
function echoGroupStart(message, color = "#000") {
|
||||
if (isDebug) {
|
||||
console.group("%c " + message, "font-size:16px;color:" + color + ";font-weight:bold;");
|
||||
}
|
||||
}
|
||||
function echoGroupEnd(message, color = "#000") {
|
||||
if (isDebug) {
|
||||
console.groupEnd();
|
||||
console.log("%c " + message, "font-size:16px;color:" + color + ";font-weight:bold;");
|
||||
}
|
||||
}
|
||||
|
||||
function isChinese(obj) {
|
||||
var reg = /^[\u0391-\uFFE5]+$/;
|
||||
if (obj != "" && !reg.test(obj)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkZm(zm) {
|
||||
var zmReg = /^[a-zA-Z]*$/;
|
||||
if (zm != "" && !zmReg.test(zm)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkInt(obj) {
|
||||
var reg = /^[0-9]+$/;
|
||||
if (obj != "" && !reg.test(obj)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkZmOrInt(zmnum) {
|
||||
var zmnumReg = /^[0-9a-zA-Z]*$/;
|
||||
if (zmnum != "" && !zmnumReg.test(zmnum)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkEmail(obj) {
|
||||
//对电子邮件的验证
|
||||
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
|
||||
if (!myreg.test(obj)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkMobile(mobile) {
|
||||
if (mobile.length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (mobile.length != 11) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(/^1[34578]\d{9}$/.test(mobile))) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkIDCard(idCard) {
|
||||
var checkFlag = new IDCard(idCard);
|
||||
if (!checkFlag.IsValid()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkDouble(value) {
|
||||
var reg = /^(-?\d+).(-?\d+)?$/
|
||||
if (reg.test(value)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkDateTime(value) {
|
||||
var reg = /^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/;
|
||||
if (reg.test(value)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkTime(value, type = "H:i:s") {
|
||||
var reg = /^((?:[0-2][0-3])|(?:[0-1][0-9])|(?:[0-9])):([0-5][0-9]|[0-9]):([0-5][0-9]|[0-9])$/;
|
||||
switch (type) {
|
||||
case 'H:i:s':
|
||||
reg = /^((?:[0-2][0-3])|(?:[0-1][0-9])|(?:[0-9])):([0-5][0-9]|[0-9]):([0-5][0-9]|[0-9])$/;
|
||||
break;
|
||||
case 'H:i':
|
||||
reg = /^((?:[0-2][0-3])|(?:[0-1][0-9])|(?:[0-9])):([0-5][0-9]|[0-9])$/;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
if (reg.test(value)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkDate(value, type = "Y-m-d") {
|
||||
var reg = /^(?:19|20)[0-9][0-9]-(?:(?:[1-9])|(?:0[1-9])|(?:1[0-2]))-(?:(?:[1-9])|(?:[0-2][1-9])|(?:[1-3][0-1]))$/;
|
||||
switch (type) {
|
||||
case 'Y-m-d':
|
||||
reg = /^(?:19|20)[0-9][0-9]-(?:(?:[1-9])|(?:0[1-9])|(?:1[0-2]))-(?:(?:[1-9])|(?:[0-2][1-9])|(?:[1-3][0-1]))$/;
|
||||
break;
|
||||
case 'm-d':
|
||||
reg = /^(?:(?:[1-9])|(?:0[1-9])|(?:1[0-2]))-(?:(?:[1-9])|(?:[0-2][1-9])|(?:[1-3][0-1]))$/;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
if (reg.test(value)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkTrainNo(value) {
|
||||
var reg = /^(C|D|G|Z|T|K|L)([0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])$/;
|
||||
if (reg.test(value.toUpperCase())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function IDCard(CardNo) {
|
||||
this.Valid = false;
|
||||
this.ID15 = '';
|
||||
this.ID18 = '';
|
||||
this.Local = '';
|
||||
if (CardNo != null) this.SetCardNo(CardNo);
|
||||
}
|
||||
|
||||
// 设置身份证号码,15位或者18位
|
||||
IDCard.prototype.SetCardNo = function (CardNo) {
|
||||
this.ID15 = '';
|
||||
this.ID18 = '';
|
||||
this.Local = '';
|
||||
CardNo = CardNo.replace(" ", "");
|
||||
var strCardNo;
|
||||
if (CardNo.length == 18) {
|
||||
pattern = /^\d{17}(\d|x|X)$/;
|
||||
if (pattern.exec(CardNo) == null) return;
|
||||
strCardNo = CardNo.toUpperCase();
|
||||
} else {
|
||||
pattern = /^\d{15}$/;
|
||||
if (pattern.exec(CardNo) == null) return;
|
||||
strCardNo = CardNo.substr(0, 6) + '19' + CardNo.substr(6, 9)
|
||||
strCardNo += this.GetVCode(strCardNo);
|
||||
}
|
||||
this.Valid = this.CheckValid(strCardNo);
|
||||
}
|
||||
|
||||
// 校验身份证有效性
|
||||
IDCard.prototype.IsValid = function () {
|
||||
return this.Valid;
|
||||
}
|
||||
|
||||
// 返回生日字符串,格式如下,1981-10-10
|
||||
IDCard.prototype.GetBirthDate = function () {
|
||||
var BirthDate = '';
|
||||
if (this.Valid) BirthDate = this.GetBirthYear() + '-' + this.GetBirthMonth() + '-' + this.GetBirthDay();
|
||||
return BirthDate;
|
||||
}
|
||||
|
||||
// 返回生日中的年,格式如下,1981
|
||||
IDCard.prototype.GetBirthYear = function () {
|
||||
var BirthYear = '';
|
||||
if (this.Valid) BirthYear = this.ID18.substr(6, 4);
|
||||
return BirthYear;
|
||||
}
|
||||
|
||||
// 返回生日中的月,格式如下,10
|
||||
IDCard.prototype.GetBirthMonth = function () {
|
||||
var BirthMonth = '';
|
||||
if (this.Valid) BirthMonth = this.ID18.substr(10, 2);
|
||||
if (BirthMonth.charAt(0) == '0') BirthMonth = BirthMonth.charAt(1);
|
||||
return BirthMonth;
|
||||
}
|
||||
|
||||
// 返回生日中的日,格式如下,10
|
||||
IDCard.prototype.GetBirthDay = function () {
|
||||
var BirthDay = '';
|
||||
if (this.Valid) BirthDay = this.ID18.substr(12, 2);
|
||||
return BirthDay;
|
||||
}
|
||||
|
||||
// 返回性别,1:男,0:女
|
||||
IDCard.prototype.GetSex = function () {
|
||||
var Sex = '';
|
||||
if (this.Valid) Sex = this.ID18.charAt(16) % 2;
|
||||
return Sex;
|
||||
}
|
||||
|
||||
// 返回15位身份证号码
|
||||
IDCard.prototype.Get15 = function () {
|
||||
var ID15 = '';
|
||||
if (this.Valid) ID15 = this.ID15;
|
||||
return ID15;
|
||||
}
|
||||
|
||||
// 返回18位身份证号码
|
||||
IDCard.prototype.Get18 = function () {
|
||||
var ID18 = '';
|
||||
if (this.Valid) ID18 = this.ID18;
|
||||
return ID18;
|
||||
}
|
||||
|
||||
// 返回所在省,例如:上海市、浙江省
|
||||
IDCard.prototype.GetLocal = function () {
|
||||
var Local = '';
|
||||
if (this.Valid) Local = this.Local;
|
||||
return Local;
|
||||
}
|
||||
|
||||
IDCard.prototype.GetVCode = function (CardNo17) {
|
||||
var Wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
|
||||
var Ai = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
|
||||
var cardNoSum = 0;
|
||||
for (var i = 0; i < CardNo17.length; i++) cardNoSum += CardNo17.charAt(i) * Wi[i];
|
||||
var seq = cardNoSum % 11;
|
||||
return Ai[seq];
|
||||
}
|
||||
|
||||
IDCard.prototype.CheckValid = function (CardNo18) {
|
||||
if (this.GetVCode(CardNo18.substr(0, 17)) != CardNo18.charAt(17)) return false;
|
||||
if (!this.IsDate(CardNo18.substr(6, 8))) return false;
|
||||
var aCity = {
|
||||
11: "北京",
|
||||
12: "天津",
|
||||
13: "河北",
|
||||
14: "山西",
|
||||
15: "内蒙古",
|
||||
21: "辽宁",
|
||||
22: "吉林",
|
||||
23: "黑龙江 ",
|
||||
31: "上海",
|
||||
32: "江苏",
|
||||
33: "浙江",
|
||||
34: "安徽",
|
||||
35: "福建",
|
||||
36: "江西",
|
||||
37: "山东",
|
||||
41: "河南",
|
||||
42: "湖北 ",
|
||||
43: "湖南",
|
||||
44: "广东",
|
||||
45: "广西",
|
||||
46: "海南",
|
||||
50: "重庆",
|
||||
51: "四川",
|
||||
52: "贵州",
|
||||
53: "云南",
|
||||
54: "西藏 ",
|
||||
61: "陕西",
|
||||
62: "甘肃",
|
||||
63: "青海",
|
||||
64: "宁夏",
|
||||
65: "新疆",
|
||||
71: "台湾",
|
||||
81: "香港",
|
||||
82: "澳门",
|
||||
91: "国外"
|
||||
};
|
||||
if (aCity[parseInt(CardNo18.substr(0, 2))] == null) return false;
|
||||
this.ID18 = CardNo18;
|
||||
this.ID15 = CardNo18.substr(0, 6) + CardNo18.substr(8, 9);
|
||||
this.Local = aCity[parseInt(CardNo18.substr(0, 2))];
|
||||
return true;
|
||||
}
|
||||
|
||||
IDCard.prototype.IsDate = function (strDate) {
|
||||
var r = strDate.match(/^(\d{1,4})(\d{1,2})(\d{1,2})$/);
|
||||
if (r == null) return false;
|
||||
var d = new Date(r[1], r[2] - 1, r[3]);
|
||||
return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[2] && d.getDate() == r[3]);
|
||||
}
|
||||
function enableElementDialogDrag() {
|
||||
var el = document;
|
||||
let minWidth = 400;
|
||||
let minHeight = 300;
|
||||
//获取弹框头部(这部分可双击全屏)
|
||||
const dialogHeaderEl = el.querySelector('.el-dialog__header');
|
||||
//弹窗
|
||||
const dragDom = el.querySelector('.el-dialog');
|
||||
//给弹窗加上overflow auto;不然缩小时框内的标签可能超出dialog
|
||||
dragDom.style.overflow = "auto";
|
||||
dialogHeaderEl.onselectstart = new Function("return false");
|
||||
//头部加上可拖动cursor
|
||||
dialogHeaderEl.style.cursor = 'move';
|
||||
// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
|
||||
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
|
||||
let moveDown = function (e) {
|
||||
// 鼠标按下,计算当前元素距离可视区的距离
|
||||
const disX = e.clientX - dialogHeaderEl.offsetLeft;
|
||||
const disY = e.clientY - dialogHeaderEl.offsetTop;
|
||||
// 获取到的值带px 正则匹配替换
|
||||
let styL, styT;
|
||||
// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
|
||||
if (sty.left.includes('%')) {
|
||||
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
|
||||
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
|
||||
} else {
|
||||
styL = +sty.left.replace(/\px/g, '');
|
||||
styT = +sty.top.replace(/\px/g, '');
|
||||
};
|
||||
document.onmousemove = function (e) {
|
||||
// 通过事件委托,计算移动的距离
|
||||
const l = e.clientX - disX;
|
||||
const t = e.clientY - disY;
|
||||
// 移动当前元素
|
||||
dragDom.style.left = l + styL + 'px';
|
||||
dragDom.style.top = t + styT + 'px';
|
||||
//将此时的位置传出去
|
||||
//binding.value({x:e.pageX,y:e.pageY})
|
||||
};
|
||||
|
||||
document.onmouseup = function (e) {
|
||||
document.onmousemove = null;
|
||||
document.onmouseup = null;
|
||||
};
|
||||
}
|
||||
dialogHeaderEl.onmousedown = moveDown;
|
||||
dragDom.onmousemove = function (e) {
|
||||
if (e.clientX > dragDom.offsetLeft + dragDom.clientWidth - 10 || dragDom.offsetLeft + 10 > e.clientX) {
|
||||
dragDom.style.cursor = 'w-resize';
|
||||
} else if (el.scrollTop + e.clientY > dragDom.offsetTop + dragDom.clientHeight - 10) {
|
||||
dragDom.style.cursor = 's-resize';
|
||||
} else {
|
||||
dragDom.style.cursor = 'default';
|
||||
dragDom.onmousedown = null;
|
||||
}
|
||||
dragDom.onmousedown = function (e) {
|
||||
const clientX = e.clientX;
|
||||
const clientY = e.clientY;
|
||||
let elW = dragDom.clientWidth;
|
||||
let elH = dragDom.clientHeight;
|
||||
let EloffsetLeft = dragDom.offsetLeft;
|
||||
let EloffsetTop = dragDom.offsetTop;
|
||||
dragDom.style.userSelect = 'none';
|
||||
let ELscrollTop = el.scrollTop;
|
||||
//判断点击的位置是不是为头部
|
||||
if (clientX > EloffsetLeft && clientX < EloffsetLeft + elW && clientY > EloffsetTop && clientY < EloffsetTop + 100) {
|
||||
//如果是头部在此就不做任何动作,以上有绑定dialogHeaderEl.onmousedown = moveDown;
|
||||
} else {
|
||||
document.onmousemove = function (e) {
|
||||
e.preventDefault(); // 移动时禁用默认事件
|
||||
//左侧鼠标拖拽位置
|
||||
if (clientX > EloffsetLeft && clientX < EloffsetLeft + 10) {
|
||||
//往左拖拽
|
||||
if (clientX > e.clientX) {
|
||||
dragDom.style.width = elW + (clientX - e.clientX) * 1 + 'px';
|
||||
}
|
||||
//往右拖拽
|
||||
if (clientX < e.clientX) {
|
||||
if (dragDom.clientWidth < minWidth) {
|
||||
} else {
|
||||
dragDom.style.width = elW - (e.clientX - clientX) * 1 + 'px';
|
||||
}
|
||||
}
|
||||
}
|
||||
//右侧鼠标拖拽位置
|
||||
if (clientX > EloffsetLeft + elW - 10 && clientX < EloffsetLeft + elW) {
|
||||
//往左拖拽
|
||||
if (clientX > e.clientX) {
|
||||
if (dragDom.clientWidth < minWidth) {
|
||||
} else {
|
||||
dragDom.style.width = elW - (clientX - e.clientX) * 1 + 'px';
|
||||
}
|
||||
}
|
||||
//往右拖拽
|
||||
if (clientX < e.clientX) {
|
||||
dragDom.style.width = elW + (e.clientX - clientX) * 1 + 'px';
|
||||
}
|
||||
}
|
||||
//底部鼠标拖拽位置
|
||||
if (ELscrollTop + clientY > EloffsetTop + elH - 20 && ELscrollTop + clientY < EloffsetTop + elH) {
|
||||
//往上拖拽
|
||||
if (clientY > e.clientY) {
|
||||
if (dragDom.clientHeight < minHeight) {
|
||||
|
||||
} else {
|
||||
dragDom.style.height = elH - (clientY - e.clientY) * 2 + 'px';
|
||||
}
|
||||
}
|
||||
//往下拖拽
|
||||
if (clientY < e.clientY) {
|
||||
dragDom.style.height = elH + (e.clientY - clientY) * 2 + 'px';
|
||||
}
|
||||
}
|
||||
};
|
||||
//拉伸结束
|
||||
document.onmouseup = function (e) {
|
||||
document.onmousemove = null;
|
||||
document.onmouseup = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var exitFullscreen = false
|
||||
//全屏功能
|
||||
function requestFullScreen(element) {
|
||||
if (exitFullscreen) {
|
||||
return exitFull();
|
||||
}
|
||||
exitFullscreen = true
|
||||
element = document.documentElement
|
||||
// 判断各种浏览器,找到正确的方法
|
||||
var requestMethod = element.requestFullScreen || //W3C
|
||||
element.webkitRequestFullScreen || //FireFox
|
||||
element.mozRequestFullScreen || //Chrome等
|
||||
element.msRequestFullScreen; //IE11
|
||||
if (requestMethod) {
|
||||
requestMethod.call(element);
|
||||
} else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
|
||||
var wscript = new ActiveXObject("WScript.Shell");
|
||||
if (wscript !== null) {
|
||||
wscript.SendKeys("{F11}");
|
||||
}
|
||||
}
|
||||
}
|
||||
//退出全屏 判断浏览器种类
|
||||
function exitFull() {
|
||||
exitFullscreen = false
|
||||
// 判断各种浏览器,找到正确的方法
|
||||
var exitMethod = document.exitFullscreen || //W3C
|
||||
document.mozCancelFullScreen || //FireFox
|
||||
document.webkitExitFullscreen || //Chrome等
|
||||
document.webkitExitFullscreen; //IE11
|
||||
if (exitMethod) {
|
||||
exitMethod.call(document);
|
||||
} else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
|
||||
var wscript = new ActiveXObject("WScript.Shell");
|
||||
if (wscript !== null) {
|
||||
wscript.SendKeys("{F11}");
|
||||
}
|
||||
}
|
||||
}
|
||||
//测试弹框
|
||||
function testalert(e) {
|
||||
app.$message.error(e);
|
||||
}
|
||||
|
||||
function readTextFile(file, callback) {
|
||||
var rawFile = new XMLHttpRequest();
|
||||
rawFile.overrideMimeType("application/json");
|
||||
rawFile.open("GET", file, true);
|
||||
rawFile.onreadystatechange = function() {
|
||||
if (rawFile.readyState === 4 && rawFile.status == "200") {
|
||||
callback(rawFile.responseText);
|
||||
}
|
||||
}
|
||||
rawFile.send(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数值保留2位小数返回(不会四舍五入)
|
||||
* @param value
|
||||
* @returns {string}
|
||||
*/
|
||||
getNumber = (value) => {
|
||||
const toFixedNum = Number(value).toFixed(3)
|
||||
return value ? toFixedNum.substring(0, toFixedNum.toString().length - 1) : '0.00'
|
||||
}
|
||||
Vendored
-3
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,570 +0,0 @@
|
||||
/**
|
||||
* @description: 图片库
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
Vue.component("Uploads", {
|
||||
template: '#Upload',
|
||||
data() {
|
||||
return {
|
||||
fullscreenLoading: false,
|
||||
visible: false,
|
||||
loading: true,
|
||||
form: {
|
||||
page: 1,
|
||||
per_page: 18
|
||||
},
|
||||
dataList: [],
|
||||
fileList: [],
|
||||
selectList: [],
|
||||
postData: PostBase,
|
||||
multiple: false, //是否支持多选
|
||||
selected_num: 0, //已选择数量
|
||||
total_num: 10, //总共可选择数量
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
save(){
|
||||
this.visible = false
|
||||
this.show('', this.selectList,true)
|
||||
},
|
||||
show(call,data,type=false){
|
||||
if (type) return this.call(data);
|
||||
this.call = call;
|
||||
this.visible = true
|
||||
this.multiple = data?data.multiple:0
|
||||
this.selected_num = data ?data.selected_num:0
|
||||
this.total_num = data ?data.total_num:10
|
||||
this.selectList = []
|
||||
this.getList()
|
||||
},
|
||||
select(index){
|
||||
if(this.multiple){
|
||||
if (this.dataList.data[index].select) {
|
||||
this.dataList.data[index].select = false
|
||||
for (let i = 0; i < this.selectList.length; i++) {
|
||||
if (this.selectList[i].url == this.dataList.data[index].attach_path) {
|
||||
this.selectList.splice(i, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(this.selectList.length + this.selected_num >= this.total_num){
|
||||
return this.$message.error('最多可选择'+ this.total_num+'文件');
|
||||
}
|
||||
this.dataList.data[index].select = true
|
||||
this.selectList.push({
|
||||
name: this.dataList.data[index].attach_name,
|
||||
url: this.dataList.data[index].attach_path
|
||||
})
|
||||
}
|
||||
}else{
|
||||
this.selectList = [];
|
||||
for (let item of this.dataList.data) {
|
||||
item.select = false
|
||||
}
|
||||
this.dataList.data[index].select = true
|
||||
this.selectList.push({
|
||||
name: this.dataList.data[index].attach_name,
|
||||
url: this.dataList.data[index].attach_path
|
||||
})
|
||||
}
|
||||
},
|
||||
changeCurrentPage(page) {
|
||||
this.form.page = page;
|
||||
this.getList();
|
||||
},
|
||||
getList() {
|
||||
var that = this;
|
||||
that.loading = true;
|
||||
axios.post('/admin/attach/getList', Object.assign({}, PostBase, that.form))
|
||||
.then(function (res) {
|
||||
that.loading = false;
|
||||
if (res.data.code == 200) {
|
||||
for (let item of res.data.data.data) {
|
||||
item.select = false
|
||||
for (let items of that.selectList) {
|
||||
if(item.attach_path == items.url){
|
||||
item.select = true
|
||||
}
|
||||
}
|
||||
}
|
||||
that.dataList = res.data.data;
|
||||
} else {
|
||||
that.$message.error(res.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.loading = false;
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
handleUploadSuccess(res, file) {
|
||||
this.fullscreenLoading = false;
|
||||
if (res.code == 200) {
|
||||
this.$message({
|
||||
message: res.message,
|
||||
type: 'success'
|
||||
});
|
||||
this.form.page = 1;
|
||||
this.getList();
|
||||
} else {
|
||||
this.$message.error(res.message);
|
||||
}
|
||||
},
|
||||
beforeUpload(file) {
|
||||
const isImage = file.type === 'image/jpeg' || file.type === 'image/png';
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isImage) {
|
||||
this.$message.error('上传图片只能是 JPG/PNG 格式!');
|
||||
}
|
||||
if (!isLt2M) {
|
||||
this.$message.error('上传头像图片大小不能超过 2MB!');
|
||||
}
|
||||
this.fullscreenLoading = true;
|
||||
return isImage && isLt2M;
|
||||
},
|
||||
}
|
||||
});
|
||||
/**
|
||||
* @description: 富文本
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
Vue.component('Ueditors', VueUeditorWrap);
|
||||
Vue.component("Ueditor", {
|
||||
template: '#Ueditor',
|
||||
// 接收父组件传递过来的参数
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
index:{
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
config: {
|
||||
// 编辑器层级的基数,默认是900
|
||||
zIndex: 9000,
|
||||
// 编辑器自动被内容撑高
|
||||
autoHeightEnabled: true,
|
||||
// 初始容器高度
|
||||
initialFrameHeight: 280,
|
||||
// 初始容器宽度
|
||||
initialFrameWidth: "100%",
|
||||
// 上传文件接口(这个地址是我为了方便各位体验文件上传功能搭建的临时接口,请勿在生产环境使用!!!部署在国外的服务器,如果无法访问,请自备梯子)
|
||||
serverUrl: "/admin/attach/uploads",
|
||||
// 给编辑区域的iframe引入一个css文件
|
||||
// iframeCssUrl: "static/UEditor/themes/iframe.css",
|
||||
// 图片操作的浮层开关
|
||||
imagePopup: false,
|
||||
// 打开右键菜单功能
|
||||
enableContextMenu: false,
|
||||
// 是否保持toolbar的位置不动,默认true
|
||||
autoFloatEnabled: false,
|
||||
// 工具栏上的所有的功能按钮和下拉框
|
||||
toolbars: [[
|
||||
'source', '|', 'undo', 'redo', '|',
|
||||
'bold', 'italic', 'underline', 'strikethrough', 'removeformat',
|
||||
// 纯文本粘贴
|
||||
'pasteplain', '|', 'forecolor', 'backcolor', 'selectall', 'cleardoc', '|',
|
||||
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
|
||||
'fontsize', '|',
|
||||
'indent', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
|
||||
'simpleupload',
|
||||
'insertimage',
|
||||
// 'insertvideo'
|
||||
]]
|
||||
},
|
||||
content: '',
|
||||
list: [],
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value(newVal) {
|
||||
this.$emit('input', newVal)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 注册自定义组件
|
||||
addCustomButtom(editorId) {
|
||||
this.setbutton(editorId)
|
||||
},
|
||||
setbutton(editorId) {
|
||||
let _this = this
|
||||
window.UE.registerUI('simpleupload', function (editor, uiName) {
|
||||
// 创建一个 button
|
||||
var btn = new window.UE.ui.Button({
|
||||
// 按钮的名字
|
||||
name: uiName,
|
||||
// 提示
|
||||
title: '插入图片',
|
||||
// 需要添加的额外样式,可指定 icon 图标,图标路径参考常见问题 2
|
||||
cssRules: '',
|
||||
// 点击时执行的命令
|
||||
onclick: () => {
|
||||
// 打开文件选择器
|
||||
app.$refs.upload.show((e) => {
|
||||
if (e.length > 0) {
|
||||
let content = e.map(item => {
|
||||
return `<p><img src="${item.url}"/></p>`
|
||||
})
|
||||
_this.inserthtml(content.join(''))
|
||||
}
|
||||
}, {
|
||||
multiple: true
|
||||
}, false);
|
||||
}
|
||||
})
|
||||
// 因为你是添加 button,所以需要返回这个 button
|
||||
return btn
|
||||
}, -1 /* 指定添加到工具栏上的哪个位置,默认时追加到最后 */ ,editorId /* 指定这个 UI 是哪个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮 */)
|
||||
},
|
||||
inserthtml (content) {
|
||||
let editor = this.$refs.Ueditor.editor
|
||||
editor.execCommand('inserthtml', content)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @description: 图片选择
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
Vue.component("Single", {
|
||||
template: '#Single',
|
||||
data() {
|
||||
return {
|
||||
drag:false,
|
||||
}
|
||||
},
|
||||
// 接收父组件传递过来的参数
|
||||
props: {
|
||||
value: {
|
||||
type: String
|
||||
},
|
||||
multiple:{ //是否支持多图选择
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
selected_num:{ //已选择的数量
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
total_num:{ //总共可选择数量
|
||||
type: Number,
|
||||
default: 10
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
selectimg() {
|
||||
if (this.multiple) {
|
||||
app.$refs.upload.show((e) =>{
|
||||
for (let item of e) {
|
||||
this.value.push(item.url)
|
||||
this.$emit('input', this.value);
|
||||
}
|
||||
}, {
|
||||
multiple: true,
|
||||
selected_num: this.selected_num,
|
||||
total_num: this.total_num,
|
||||
}, false);
|
||||
} else {
|
||||
app.$refs.upload.show((e) =>{
|
||||
this.$emit('input', e[0].url);
|
||||
}, {}, false);
|
||||
}
|
||||
},
|
||||
deles(s) {
|
||||
if (this.multiple) {
|
||||
this.value.splice(s,1)
|
||||
this.$emit('input', this.value);
|
||||
} else {
|
||||
this.$emit('input', '');
|
||||
}
|
||||
},
|
||||
//开始拖拽事件
|
||||
onStart(){
|
||||
this.drag = true;
|
||||
},
|
||||
//拖拽结束事件
|
||||
onEnd() {
|
||||
this.drag = false;
|
||||
this.$emit('input', this.value);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @description: SKU
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
SkuForm.default.install(Vue);
|
||||
Vue.component("vue-sku", {
|
||||
template: '#skuforms',
|
||||
// 接收父组件传递过来的参数
|
||||
props: {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
inputVisible: false,
|
||||
inputValue: '',
|
||||
sourceAttribute: [],
|
||||
structure: [
|
||||
{
|
||||
name: 'goods_price',
|
||||
type: 'input',
|
||||
label: '商品价格',
|
||||
required: true,
|
||||
validate: (data, index, callback) => {
|
||||
if (parseFloat(data[index].goods_price) < 0.01) callback(new Error('商品价格不能小于0.01'))
|
||||
if (isNaN(data[index].goods_price)) callback(new Error('请输入正确的商品价格'))
|
||||
callback()
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'stock',
|
||||
type: 'input',
|
||||
label: '库存',
|
||||
required: true,
|
||||
validate: (data, index, callback) => {
|
||||
if ( parseInt(data[index].stock) < 0) callback(new Error('库存不能小于0'))
|
||||
if (isNaN(data[index].stock)) callback(new Error('请输入正确的库存'))
|
||||
callback()
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'line_price',
|
||||
type: 'input',
|
||||
label: '划线价格',
|
||||
validate: (data, index, callback) => {
|
||||
if (isNaN(data[index].line_price)) callback(new Error('请输入正确的划线价格'))
|
||||
callback()
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'goods_weight',
|
||||
type: 'input',
|
||||
label: '商品重量',
|
||||
validate: (data, index, callback) => {
|
||||
if (isNaN(data[index].goods_weight)) callback(new Error('请输入正确的商品重量'))
|
||||
callback()
|
||||
}
|
||||
},
|
||||
],
|
||||
attribute: [],
|
||||
sku: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showInput() {
|
||||
this.inputVisible = true;
|
||||
this.$nextTick(_ => {
|
||||
this.$refs.saveTagInput.$refs.input.focus();
|
||||
});
|
||||
},
|
||||
|
||||
handleInputConfirm() {
|
||||
let inputValue = this.inputValue;
|
||||
this.sourceAttribute.push(
|
||||
{
|
||||
name: inputValue,
|
||||
item: []
|
||||
}
|
||||
);
|
||||
this.$refs.skuForm.init()
|
||||
this.inputVisible = false;
|
||||
this.inputValue = '';
|
||||
},
|
||||
|
||||
setdata(sku, attribute) {
|
||||
setTimeout(() => {
|
||||
this.sourceAttribute = attribute
|
||||
setTimeout(() => {
|
||||
this.attribute = attribute
|
||||
setTimeout(() => {
|
||||
this.sku = sku
|
||||
// 切记,必须在 attribute、sku 数据都加载后再执行 init() 方法
|
||||
this.$refs.skuForm.init()
|
||||
}, 100)
|
||||
}, 100)
|
||||
}, 100)
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @description: 商品库
|
||||
* @param {*}
|
||||
* @return {*}
|
||||
*/
|
||||
Vue.component("Goodslists", {
|
||||
template: '#Goodslist',
|
||||
data() {
|
||||
return {
|
||||
fullscreenLoading: false,
|
||||
visible: false,
|
||||
loading: true,
|
||||
form: {
|
||||
page: 1,
|
||||
per_page: 5
|
||||
},
|
||||
search: {
|
||||
keyword: "",
|
||||
filter: "goods_name",
|
||||
classify: '',
|
||||
},
|
||||
dataList: [],
|
||||
dataList2: [],
|
||||
selectList: [],
|
||||
categoryList: [],
|
||||
postData: PostBase,
|
||||
cascaderProps: {
|
||||
value: 'goods_category_id',
|
||||
label: 'name',
|
||||
children: 'children',
|
||||
checkStrictly: true,
|
||||
emitPath: false
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
save(){
|
||||
this.visible = false
|
||||
let data = this.unique2(this.selectList.concat(this.selectList2))
|
||||
this.$refs.multipleTable.clearSelection();
|
||||
this.show('', data, true)
|
||||
},
|
||||
show(call, data=[], type = false) {
|
||||
if (type) return this.call(data);
|
||||
this.call = call;
|
||||
this.visible = true
|
||||
this.selectList2 = JSON.parse(JSON.stringify(data));
|
||||
this.init()
|
||||
},
|
||||
handleClose(done) {
|
||||
this.$refs.multipleTable.clearSelection();
|
||||
done();
|
||||
},
|
||||
cancels() {
|
||||
this.$refs.multipleTable.clearSelection();
|
||||
this.visible = false
|
||||
},
|
||||
init() {
|
||||
this.form = {
|
||||
page: 1,
|
||||
per_page: 5
|
||||
}
|
||||
this.search = {
|
||||
keyword: "",
|
||||
filter: "goods_name",
|
||||
classify: '',
|
||||
}
|
||||
this.getcategory()
|
||||
},
|
||||
|
||||
getList_search(val) {
|
||||
if(val==0){
|
||||
this.search = {
|
||||
keyword: "",
|
||||
filter: "goods_name",
|
||||
classify: '',
|
||||
}
|
||||
}
|
||||
this.form.page = 1;
|
||||
this.getList();
|
||||
},
|
||||
//获取商品分类
|
||||
getcategory() {
|
||||
var that = this;
|
||||
that.loading = true;
|
||||
axios.post('/admin/goodsCategory/getList', Object.assign({}, PostBase))
|
||||
.then(function (response) {
|
||||
if (response.data.code == CODE_SUCCESS) {
|
||||
that.getList();
|
||||
that.categoryList = response.data.data;
|
||||
} else {
|
||||
that.$message.error(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.loading = false;
|
||||
that.$message.error('服务器内部错误');
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
getList() {
|
||||
var that = this;
|
||||
that.loading = true;
|
||||
axios.post('/admin/goods/getList', Object.assign({}, PostBase, that.form, that.search, {
|
||||
tabPane: 'sale'
|
||||
}))
|
||||
.then(function (res) {
|
||||
that.loading = false;
|
||||
if (res.data.code == 200) {
|
||||
that.dataList = res.data.data;
|
||||
for (let item of that.dataList.data) {
|
||||
for (let i = 0; i < that.selectList2.length; i++) {
|
||||
if (item.goods_id == that.selectList2[i]) {
|
||||
if (that.selectList.indexOf(item.goods_id) == -1) {
|
||||
that.$nextTick(() => {
|
||||
that.$refs.multipleTable.toggleRowSelection(item, true);
|
||||
})
|
||||
}
|
||||
that.selectList2.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
that.$message.error(res.data.message);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
that.loading = false;
|
||||
that.$message.error('服务器内部错误');
|
||||
});
|
||||
},
|
||||
changeSelection(list) {
|
||||
var that = this;
|
||||
that.unique(list)
|
||||
that.selectList = [];
|
||||
for (var index in list) {
|
||||
that.selectList.push(list[index].goods_id);
|
||||
}
|
||||
},
|
||||
changeCurrentPage(page) {
|
||||
this.form.page = page;
|
||||
this.getList();
|
||||
},
|
||||
|
||||
unique(arr){
|
||||
for(var i=0; i<arr.length; i++){
|
||||
for(var j=i+1; j<arr.length; j++){
|
||||
if(arr[i].goods_id==arr[j].goods_id){ //第一个等同于第二个,splice方法删除第二个
|
||||
arr.splice(j,1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
unique2(arr){
|
||||
for(var i=0; i<arr.length; i++){
|
||||
for(var j=i+1; j<arr.length; j++){
|
||||
if(arr[i]==arr[j]){ //第一个等同于第二个,splice方法删除第二个
|
||||
arr.splice(j,1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
});
|
||||
-17
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,298 +0,0 @@
|
||||
/**
|
||||
* Created by jf on 2015/9/11.
|
||||
* Modified by bear on 2016/9/7.
|
||||
*/
|
||||
$(function () {
|
||||
var pageManager = {
|
||||
$container: $('#container'),
|
||||
_pageStack: [],
|
||||
_configs: [],
|
||||
_pageAppend: function(){},
|
||||
_defaultPage: null,
|
||||
_pageIndex: 1,
|
||||
setDefault: function (defaultPage) {
|
||||
this._defaultPage = this._find('name', defaultPage);
|
||||
return this;
|
||||
},
|
||||
setPageAppend: function (pageAppend) {
|
||||
this._pageAppend = pageAppend;
|
||||
return this;
|
||||
},
|
||||
init: function () {
|
||||
var self = this;
|
||||
|
||||
$(window).on('hashchange', function () {
|
||||
var state = history.state || {};
|
||||
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
|
||||
var page = self._find('url', url) || self._defaultPage;
|
||||
if (state._pageIndex <= self._pageIndex || self._findInStack(url)) {
|
||||
self._back(page);
|
||||
} else {
|
||||
self._go(page);
|
||||
}
|
||||
});
|
||||
|
||||
if (history.state && history.state._pageIndex) {
|
||||
this._pageIndex = history.state._pageIndex;
|
||||
}
|
||||
|
||||
this._pageIndex--;
|
||||
|
||||
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
|
||||
var page = self._find('url', url) || self._defaultPage;
|
||||
this._go(page);
|
||||
return this;
|
||||
},
|
||||
push: function (config) {
|
||||
this._configs.push(config);
|
||||
return this;
|
||||
},
|
||||
go: function (to) {
|
||||
var config = this._find('name', to);
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
location.hash = config.url;
|
||||
},
|
||||
_go: function (config) {
|
||||
this._pageIndex ++;
|
||||
|
||||
history.replaceState && history.replaceState({_pageIndex: this._pageIndex}, '', location.href);
|
||||
|
||||
var html = $(config.template).html();
|
||||
var $html = $(html).addClass('slideIn').addClass(config.name);
|
||||
$html.on('animationend webkitAnimationEnd', function(){
|
||||
$html.removeClass('slideIn').addClass('js_show');
|
||||
});
|
||||
this.$container.append($html);
|
||||
this._pageAppend.call(this, $html);
|
||||
this._pageStack.push({
|
||||
config: config,
|
||||
dom: $html
|
||||
});
|
||||
|
||||
if (!config.isBind) {
|
||||
this._bind(config);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
back: function () {
|
||||
history.back();
|
||||
},
|
||||
_back: function (config) {
|
||||
this._pageIndex --;
|
||||
|
||||
var stack = this._pageStack.pop();
|
||||
if (!stack) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
|
||||
var found = this._findInStack(url);
|
||||
if (!found) {
|
||||
var html = $(config.template).html();
|
||||
var $html = $(html).addClass('js_show').addClass(config.name);
|
||||
$html.insertBefore(stack.dom);
|
||||
|
||||
if (!config.isBind) {
|
||||
this._bind(config);
|
||||
}
|
||||
|
||||
this._pageStack.push({
|
||||
config: config,
|
||||
dom: $html
|
||||
});
|
||||
}
|
||||
|
||||
stack.dom.addClass('slideOut').on('animationend webkitAnimationEnd', function () {
|
||||
stack.dom.remove();
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
_findInStack: function (url) {
|
||||
var found = null;
|
||||
for(var i = 0, len = this._pageStack.length; i < len; i++){
|
||||
var stack = this._pageStack[i];
|
||||
if (stack.config.url === url) {
|
||||
found = stack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
},
|
||||
_find: function (key, value) {
|
||||
var page = null;
|
||||
for (var i = 0, len = this._configs.length; i < len; i++) {
|
||||
if (this._configs[i][key] === value) {
|
||||
page = this._configs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return page;
|
||||
},
|
||||
_bind: function (page) {
|
||||
var events = page.events || {};
|
||||
for (var t in events) {
|
||||
for (var type in events[t]) {
|
||||
this.$container.on(type, t, events[t][type]);
|
||||
}
|
||||
}
|
||||
page.isBind = true;
|
||||
}
|
||||
};
|
||||
|
||||
function fastClick(){
|
||||
var supportTouch = function(){
|
||||
try {
|
||||
document.createEvent("TouchEvent");
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}();
|
||||
var _old$On = $.fn.on;
|
||||
|
||||
$.fn.on = function(){
|
||||
if(/click/.test(arguments[0]) && typeof arguments[1] == 'function' && supportTouch){ // 只扩展支持touch的当前元素的click事件
|
||||
var touchStartY, callback = arguments[1];
|
||||
_old$On.apply(this, ['touchstart', function(e){
|
||||
touchStartY = e.changedTouches[0].clientY;
|
||||
}]);
|
||||
_old$On.apply(this, ['touchend', function(e){
|
||||
if (Math.abs(e.changedTouches[0].clientY - touchStartY) > 10) return;
|
||||
|
||||
e.preventDefault();
|
||||
callback.apply(this, [e]);
|
||||
}]);
|
||||
}else{
|
||||
_old$On.apply(this, arguments);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
function preload(){
|
||||
$(window).on("load", function(){
|
||||
var imgList = [
|
||||
"./images/layers/content.png",
|
||||
"./images/layers/navigation.png",
|
||||
"./images/layers/popout.png",
|
||||
"./images/layers/transparent.gif"
|
||||
];
|
||||
for (var i = 0, len = imgList.length; i < len; ++i) {
|
||||
new Image().src = imgList[i];
|
||||
}
|
||||
});
|
||||
}
|
||||
function androidInputBugFix(){
|
||||
// .container 设置了 overflow 属性, 导致 Android 手机下输入框获取焦点时, 输入法挡住输入框的 bug
|
||||
// 相关 issue: https://github.com/weui/weui/issues/15
|
||||
// 解决方法:
|
||||
// 0. .container 去掉 overflow 属性, 但此 demo 下会引发别的问题
|
||||
// 1. 参考 http://stackoverflow.com/questions/23757345/android-does-not-correctly-scroll-on-input-focus-if-not-body-element
|
||||
// Android 手机下, input 或 textarea 元素聚焦时, 主动滚一把
|
||||
if (/Android/gi.test(navigator.userAgent)) {
|
||||
window.addEventListener('resize', function () {
|
||||
if (document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA') {
|
||||
window.setTimeout(function () {
|
||||
document.activeElement.scrollIntoViewIfNeeded();
|
||||
}, 0);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function setJSAPI(){
|
||||
return;
|
||||
var option = {
|
||||
title: 'WeUI, 为微信 Web 服务量身设计',
|
||||
desc: 'WeUI, 为微信 Web 服务量身设计',
|
||||
link: "https://weui.io",
|
||||
imgUrl: 'https://mmbiz.qpic.cn/mmemoticon/ajNVdqHZLLA16apETUPXh9Q5GLpSic7lGuiaic0jqMt4UY8P4KHSBpEWgM7uMlbxxnVR7596b3NPjUfwg7cFbfCtA/0'
|
||||
};
|
||||
|
||||
$.getJSON('https://weui.io/api/sign?url=' + encodeURIComponent(location.href.split('#')[0]), function (res) {
|
||||
wx.config({
|
||||
beta: true,
|
||||
debug: false,
|
||||
appId: res.appid,
|
||||
timestamp: res.timestamp,
|
||||
nonceStr: res.nonceStr,
|
||||
signature: res.signature,
|
||||
jsApiList: [
|
||||
'onMenuShareTimeline',
|
||||
'onMenuShareAppMessage',
|
||||
'onMenuShareQQ',
|
||||
'onMenuShareWeibo',
|
||||
'onMenuShareQZone',
|
||||
// 'setNavigationBarColor',
|
||||
'setBounceBackground'
|
||||
]
|
||||
});
|
||||
wx.ready(function () {
|
||||
/*
|
||||
wx.invoke('setNavigationBarColor', {
|
||||
color: '#F8F8F8'
|
||||
});
|
||||
*/
|
||||
wx.invoke('setBounceBackground', {
|
||||
'backgroundColor': '#F8F8F8',
|
||||
'footerBounceColor' : '#F8F8F8'
|
||||
});
|
||||
wx.onMenuShareTimeline(option);
|
||||
wx.onMenuShareQQ(option);
|
||||
wx.onMenuShareAppMessage({
|
||||
title: 'WeUI',
|
||||
desc: '为微信 Web 服务量身设计',
|
||||
link: location.href,
|
||||
imgUrl: 'https://mmbiz.qpic.cn/mmemoticon/ajNVdqHZLLA16apETUPXh9Q5GLpSic7lGuiaic0jqMt4UY8P4KHSBpEWgM7uMlbxxnVR7596b3NPjUfwg7cFbfCtA/0'
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
function setPageManager(){
|
||||
var pages = {}, tpls = $('script[type="text/html"]');
|
||||
|
||||
for (var i = 0, len = tpls.length; i < len; ++i) {
|
||||
var tpl = tpls[i], name = tpl.id.replace(/tpl_/, '');
|
||||
pages[name] = {
|
||||
name: name,
|
||||
url: '#' + name,
|
||||
template: '#' + tpl.id
|
||||
};
|
||||
}
|
||||
pages.home.url = '#';
|
||||
|
||||
for (var page in pages) {
|
||||
pageManager.push(pages[page]);
|
||||
}
|
||||
pageManager
|
||||
.setPageAppend(function($html){
|
||||
var $foot = $html.find('.page__ft');
|
||||
if($foot.length < 1) return;
|
||||
|
||||
var winH = $(window).height();
|
||||
if($foot.position().top + $foot.height() < winH){
|
||||
$foot.addClass('j_bottom');
|
||||
}else{
|
||||
$foot.removeClass('j_bottom');
|
||||
}
|
||||
})
|
||||
.setDefault('home')
|
||||
.init();
|
||||
}
|
||||
|
||||
function init(){
|
||||
preload();
|
||||
fastClick();
|
||||
androidInputBugFix();
|
||||
setJSAPI();
|
||||
setPageManager();
|
||||
|
||||
window.pageManager = pageManager;
|
||||
window.home = function(){
|
||||
location.hash = '';
|
||||
};
|
||||
}
|
||||
init();
|
||||
});
|
||||
@@ -1,841 +0,0 @@
|
||||
;(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @preserve FastClick: polyfill to remove click delays on browsers with touch UIs.
|
||||
*
|
||||
* @codingstandard ftlabs-jsv2
|
||||
* @copyright The Financial Times Limited [All Rights Reserved]
|
||||
* @license MIT License (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
/*jslint browser:true, node:true*/
|
||||
/*global define, Event, Node*/
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate fast-clicking listeners on the specified layer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Element} layer The layer to listen on
|
||||
* @param {Object} [options={}] The options to override the defaults
|
||||
*/
|
||||
function FastClick(layer, options) {
|
||||
var oldOnClick;
|
||||
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Whether a click is currently being tracked.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
this.trackingClick = false;
|
||||
|
||||
|
||||
/**
|
||||
* Timestamp for when click tracking started.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.trackingClickStart = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The element being tracked for a click.
|
||||
*
|
||||
* @type EventTarget
|
||||
*/
|
||||
this.targetElement = null;
|
||||
|
||||
|
||||
/**
|
||||
* X-coordinate of touch start event.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchStartX = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Y-coordinate of touch start event.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchStartY = 0;
|
||||
|
||||
|
||||
/**
|
||||
* ID of the last touch, retrieved from Touch.identifier.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.lastTouchIdentifier = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Touchmove boundary, beyond which a click will be cancelled.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchBoundary = options.touchBoundary || 10;
|
||||
|
||||
|
||||
/**
|
||||
* The FastClick layer.
|
||||
*
|
||||
* @type Element
|
||||
*/
|
||||
this.layer = layer;
|
||||
|
||||
/**
|
||||
* The minimum time between tap(touchstart and touchend) events
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.tapDelay = options.tapDelay || 200;
|
||||
|
||||
/**
|
||||
* The maximum time for a tap
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.tapTimeout = options.tapTimeout || 700;
|
||||
|
||||
if (FastClick.notNeeded(layer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some old versions of Android don't have Function.prototype.bind
|
||||
function bind(method, context) {
|
||||
return function() { return method.apply(context, arguments); };
|
||||
}
|
||||
|
||||
|
||||
var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'];
|
||||
var context = this;
|
||||
for (var i = 0, l = methods.length; i < l; i++) {
|
||||
context[methods[i]] = bind(context[methods[i]], context);
|
||||
}
|
||||
|
||||
// Set up event handlers as required
|
||||
if (deviceIsAndroid) {
|
||||
layer.addEventListener('mouseover', this.onMouse, true);
|
||||
layer.addEventListener('mousedown', this.onMouse, true);
|
||||
layer.addEventListener('mouseup', this.onMouse, true);
|
||||
}
|
||||
|
||||
layer.addEventListener('click', this.onClick, true);
|
||||
layer.addEventListener('touchstart', this.onTouchStart, false);
|
||||
layer.addEventListener('touchmove', this.onTouchMove, false);
|
||||
layer.addEventListener('touchend', this.onTouchEnd, false);
|
||||
layer.addEventListener('touchcancel', this.onTouchCancel, false);
|
||||
|
||||
// Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
|
||||
// which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
|
||||
// layer when they are cancelled.
|
||||
if (!Event.prototype.stopImmediatePropagation) {
|
||||
layer.removeEventListener = function(type, callback, capture) {
|
||||
var rmv = Node.prototype.removeEventListener;
|
||||
if (type === 'click') {
|
||||
rmv.call(layer, type, callback.hijacked || callback, capture);
|
||||
} else {
|
||||
rmv.call(layer, type, callback, capture);
|
||||
}
|
||||
};
|
||||
|
||||
layer.addEventListener = function(type, callback, capture) {
|
||||
var adv = Node.prototype.addEventListener;
|
||||
if (type === 'click') {
|
||||
adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
|
||||
if (!event.propagationStopped) {
|
||||
callback(event);
|
||||
}
|
||||
}), capture);
|
||||
} else {
|
||||
adv.call(layer, type, callback, capture);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// If a handler is already declared in the element's onclick attribute, it will be fired before
|
||||
// FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
|
||||
// adding it as listener.
|
||||
if (typeof layer.onclick === 'function') {
|
||||
|
||||
// Android browser on at least 3.2 requires a new reference to the function in layer.onclick
|
||||
// - the old one won't work if passed to addEventListener directly.
|
||||
oldOnClick = layer.onclick;
|
||||
layer.addEventListener('click', function(event) {
|
||||
oldOnClick(event);
|
||||
}, false);
|
||||
layer.onclick = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows Phone 8.1 fakes user agent string to look like Android and iPhone.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
|
||||
|
||||
/**
|
||||
* Android requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone;
|
||||
|
||||
|
||||
/**
|
||||
* iOS requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
|
||||
|
||||
|
||||
/**
|
||||
* iOS 4 requires an exception for select elements.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
|
||||
|
||||
|
||||
/**
|
||||
* iOS 6.0-7.* requires the target element to be manually derived
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent);
|
||||
|
||||
/**
|
||||
* BlackBerry requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0;
|
||||
|
||||
/**
|
||||
* Determine whether a given element requires a native click.
|
||||
*
|
||||
* @param {EventTarget|Element} target Target DOM element
|
||||
* @returns {boolean} Returns true if the element needs a native click
|
||||
*/
|
||||
FastClick.prototype.needsClick = function(target) {
|
||||
switch (target.nodeName.toLowerCase()) {
|
||||
|
||||
// Don't send a synthetic click to disabled inputs (issue #62)
|
||||
case 'button':
|
||||
case 'select':
|
||||
case 'textarea':
|
||||
if (target.disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'input':
|
||||
|
||||
// File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
|
||||
if ((deviceIsIOS && target.type === 'file') || target.disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'label':
|
||||
case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
|
||||
case 'video':
|
||||
return true;
|
||||
}
|
||||
|
||||
return (/\bneedsclick\b/).test(target.className);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether a given element requires a call to focus to simulate click into element.
|
||||
*
|
||||
* @param {EventTarget|Element} target Target DOM element
|
||||
* @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
|
||||
*/
|
||||
FastClick.prototype.needsFocus = function(target) {
|
||||
switch (target.nodeName.toLowerCase()) {
|
||||
case 'textarea':
|
||||
return true;
|
||||
case 'select':
|
||||
return !deviceIsAndroid;
|
||||
case 'input':
|
||||
switch (target.type) {
|
||||
case 'button':
|
||||
case 'checkbox':
|
||||
case 'file':
|
||||
case 'image':
|
||||
case 'radio':
|
||||
case 'submit':
|
||||
return false;
|
||||
}
|
||||
|
||||
// No point in attempting to focus disabled inputs
|
||||
return !target.disabled && !target.readOnly;
|
||||
default:
|
||||
return (/\bneedsfocus\b/).test(target.className);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Send a click event to the specified element.
|
||||
*
|
||||
* @param {EventTarget|Element} targetElement
|
||||
* @param {Event} event
|
||||
*/
|
||||
FastClick.prototype.sendClick = function(targetElement, event) {
|
||||
var clickEvent, touch;
|
||||
|
||||
// On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
|
||||
if (document.activeElement && document.activeElement !== targetElement) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
touch = event.changedTouches[0];
|
||||
|
||||
// Synthesise a click event, with an extra attribute so it can be tracked
|
||||
clickEvent = document.createEvent('MouseEvents');
|
||||
clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
|
||||
clickEvent.forwardedTouchEvent = true;
|
||||
targetElement.dispatchEvent(clickEvent);
|
||||
};
|
||||
|
||||
FastClick.prototype.determineEventType = function(targetElement) {
|
||||
|
||||
//Issue #159: Android Chrome Select Box does not open with a synthetic click event
|
||||
if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') {
|
||||
return 'mousedown';
|
||||
}
|
||||
|
||||
return 'click';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {EventTarget|Element} targetElement
|
||||
*/
|
||||
FastClick.prototype.focus = function(targetElement) {
|
||||
var length;
|
||||
|
||||
// Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
|
||||
if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
|
||||
length = targetElement.value.length;
|
||||
targetElement.setSelectionRange(length, length);
|
||||
} else {
|
||||
targetElement.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
|
||||
*
|
||||
* @param {EventTarget|Element} targetElement
|
||||
*/
|
||||
FastClick.prototype.updateScrollParent = function(targetElement) {
|
||||
var scrollParent, parentElement;
|
||||
|
||||
scrollParent = targetElement.fastClickScrollParent;
|
||||
|
||||
// Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
|
||||
// target element was moved to another parent.
|
||||
if (!scrollParent || !scrollParent.contains(targetElement)) {
|
||||
parentElement = targetElement;
|
||||
do {
|
||||
if (parentElement.scrollHeight > parentElement.offsetHeight) {
|
||||
scrollParent = parentElement;
|
||||
targetElement.fastClickScrollParent = parentElement;
|
||||
break;
|
||||
}
|
||||
|
||||
parentElement = parentElement.parentElement;
|
||||
} while (parentElement);
|
||||
}
|
||||
|
||||
// Always update the scroll top tracker if possible.
|
||||
if (scrollParent) {
|
||||
scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {EventTarget} targetElement
|
||||
* @returns {Element|EventTarget}
|
||||
*/
|
||||
FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
|
||||
|
||||
// On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
|
||||
if (eventTarget.nodeType === Node.TEXT_NODE) {
|
||||
return eventTarget.parentNode;
|
||||
}
|
||||
|
||||
return eventTarget;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch start, record the position and scroll offset.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchStart = function(event) {
|
||||
var targetElement, touch, selection;
|
||||
|
||||
// Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111).
|
||||
if (event.targetTouches.length > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
targetElement = this.getTargetElementFromEventTarget(event.target);
|
||||
touch = event.targetTouches[0];
|
||||
|
||||
if (deviceIsIOS) {
|
||||
|
||||
// Only trusted events will deselect text on iOS (issue #49)
|
||||
selection = window.getSelection();
|
||||
if (selection.rangeCount && !selection.isCollapsed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!deviceIsIOS4) {
|
||||
|
||||
// Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
|
||||
// when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
|
||||
// with the same identifier as the touch event that previously triggered the click that triggered the alert.
|
||||
// Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
|
||||
// immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
|
||||
// Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string,
|
||||
// which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long,
|
||||
// random integers, it's safe to to continue if the identifier is 0 here.
|
||||
if (touch.identifier && touch.identifier === this.lastTouchIdentifier) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.lastTouchIdentifier = touch.identifier;
|
||||
|
||||
// If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
|
||||
// 1) the user does a fling scroll on the scrollable layer
|
||||
// 2) the user stops the fling scroll with another tap
|
||||
// then the event.target of the last 'touchend' event will be the element that was under the user's finger
|
||||
// when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
|
||||
// is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
|
||||
this.updateScrollParent(targetElement);
|
||||
}
|
||||
}
|
||||
|
||||
this.trackingClick = true;
|
||||
this.trackingClickStart = event.timeStamp;
|
||||
this.targetElement = targetElement;
|
||||
|
||||
this.touchStartX = touch.pageX;
|
||||
this.touchStartY = touch.pageY;
|
||||
|
||||
// Prevent phantom clicks on fast double-tap (issue #36)
|
||||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.touchHasMoved = function(event) {
|
||||
var touch = event.changedTouches[0], boundary = this.touchBoundary;
|
||||
|
||||
if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the last position.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchMove = function(event) {
|
||||
if (!this.trackingClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the touch has moved, cancel the click tracking
|
||||
if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
|
||||
this.trackingClick = false;
|
||||
this.targetElement = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to find the labelled control for the given label element.
|
||||
*
|
||||
* @param {EventTarget|HTMLLabelElement} labelElement
|
||||
* @returns {Element|null}
|
||||
*/
|
||||
FastClick.prototype.findControl = function(labelElement) {
|
||||
|
||||
// Fast path for newer browsers supporting the HTML5 control attribute
|
||||
if (labelElement.control !== undefined) {
|
||||
return labelElement.control;
|
||||
}
|
||||
|
||||
// All browsers under test that support touch events also support the HTML5 htmlFor attribute
|
||||
if (labelElement.htmlFor) {
|
||||
return document.getElementById(labelElement.htmlFor);
|
||||
}
|
||||
|
||||
// If no for attribute exists, attempt to retrieve the first labellable descendant element
|
||||
// the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
|
||||
return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch end, determine whether to send a click event at once.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchEnd = function(event) {
|
||||
var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
|
||||
|
||||
if (!this.trackingClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent phantom clicks on fast double-tap (issue #36)
|
||||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
|
||||
this.cancelNextClick = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset to prevent wrong click cancel on input (issue #156).
|
||||
this.cancelNextClick = false;
|
||||
|
||||
this.lastClickTime = event.timeStamp;
|
||||
|
||||
trackingClickStart = this.trackingClickStart;
|
||||
this.trackingClick = false;
|
||||
this.trackingClickStart = 0;
|
||||
|
||||
// On some iOS devices, the targetElement supplied with the event is invalid if the layer
|
||||
// is performing a transition or scroll, and has to be re-detected manually. Note that
|
||||
// for this to function correctly, it must be called *after* the event target is checked!
|
||||
// See issue #57; also filed as rdar://13048589 .
|
||||
if (deviceIsIOSWithBadTarget) {
|
||||
touch = event.changedTouches[0];
|
||||
|
||||
// In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null
|
||||
targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
|
||||
targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent;
|
||||
}
|
||||
|
||||
targetTagName = targetElement.tagName.toLowerCase();
|
||||
if (targetTagName === 'label') {
|
||||
forElement = this.findControl(targetElement);
|
||||
if (forElement) {
|
||||
this.focus(targetElement);
|
||||
if (deviceIsAndroid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
targetElement = forElement;
|
||||
}
|
||||
} else if (this.needsFocus(targetElement)) {
|
||||
|
||||
// Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through.
|
||||
// Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37).
|
||||
if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) {
|
||||
this.targetElement = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.focus(targetElement);
|
||||
this.sendClick(targetElement, event);
|
||||
|
||||
// Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
|
||||
// Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others)
|
||||
if (!deviceIsIOS || targetTagName !== 'select') {
|
||||
this.targetElement = null;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceIsIOS && !deviceIsIOS4) {
|
||||
|
||||
// Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
|
||||
// and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
|
||||
scrollParent = targetElement.fastClickScrollParent;
|
||||
if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent the actual click from going though - unless the target node is marked as requiring
|
||||
// real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
|
||||
if (!this.needsClick(targetElement)) {
|
||||
event.preventDefault();
|
||||
this.sendClick(targetElement, event);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch cancel, stop tracking the click.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
FastClick.prototype.onTouchCancel = function() {
|
||||
this.trackingClick = false;
|
||||
this.targetElement = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine mouse events which should be permitted.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onMouse = function(event) {
|
||||
|
||||
// If a target element was never set (because a touch event was never fired) allow the event
|
||||
if (!this.targetElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.forwardedTouchEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Programmatically generated events targeting a specific element should be permitted
|
||||
if (!event.cancelable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derive and check the target element to see whether the mouse event needs to be permitted;
|
||||
// unless explicitly enabled, prevent non-touch click events from triggering actions,
|
||||
// to prevent ghost/doubleclicks.
|
||||
if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
|
||||
|
||||
// Prevent any user-added listeners declared on FastClick element from being fired.
|
||||
if (event.stopImmediatePropagation) {
|
||||
event.stopImmediatePropagation();
|
||||
} else {
|
||||
|
||||
// Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
|
||||
event.propagationStopped = true;
|
||||
}
|
||||
|
||||
// Cancel the event
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the mouse event is permitted, return true for the action to go through.
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On actual clicks, determine whether this is a touch-generated click, a click action occurring
|
||||
* naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
|
||||
* an actual click which should be permitted.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onClick = function(event) {
|
||||
var permitted;
|
||||
|
||||
// It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early.
|
||||
if (this.trackingClick) {
|
||||
this.targetElement = null;
|
||||
this.trackingClick = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target.
|
||||
if (event.target.type === 'submit' && event.detail === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
permitted = this.onMouse(event);
|
||||
|
||||
// Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through.
|
||||
if (!permitted) {
|
||||
this.targetElement = null;
|
||||
}
|
||||
|
||||
// If clicks are permitted, return true for the action to go through.
|
||||
return permitted;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove all FastClick's event listeners.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
FastClick.prototype.destroy = function() {
|
||||
var layer = this.layer;
|
||||
|
||||
if (deviceIsAndroid) {
|
||||
layer.removeEventListener('mouseover', this.onMouse, true);
|
||||
layer.removeEventListener('mousedown', this.onMouse, true);
|
||||
layer.removeEventListener('mouseup', this.onMouse, true);
|
||||
}
|
||||
|
||||
layer.removeEventListener('click', this.onClick, true);
|
||||
layer.removeEventListener('touchstart', this.onTouchStart, false);
|
||||
layer.removeEventListener('touchmove', this.onTouchMove, false);
|
||||
layer.removeEventListener('touchend', this.onTouchEnd, false);
|
||||
layer.removeEventListener('touchcancel', this.onTouchCancel, false);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether FastClick is needed.
|
||||
*
|
||||
* @param {Element} layer The layer to listen on
|
||||
*/
|
||||
FastClick.notNeeded = function(layer) {
|
||||
var metaViewport;
|
||||
var chromeVersion;
|
||||
var blackberryVersion;
|
||||
var firefoxVersion;
|
||||
|
||||
// Devices that don't support touch don't need FastClick
|
||||
if (typeof window.ontouchstart === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Chrome version - zero for other browsers
|
||||
chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1];
|
||||
|
||||
if (chromeVersion) {
|
||||
|
||||
if (deviceIsAndroid) {
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
|
||||
if (metaViewport) {
|
||||
// Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
|
||||
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// Chrome 32 and above with width=device-width or less don't need FastClick
|
||||
if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Chrome desktop doesn't need FastClick (issue #15)
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceIsBlackBerry10) {
|
||||
blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/);
|
||||
|
||||
// BlackBerry 10.3+ does not require Fastclick library.
|
||||
// https://github.com/ftlabs/fastclick/issues/251
|
||||
if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) {
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
|
||||
if (metaViewport) {
|
||||
// user-scalable=no eliminates click delay.
|
||||
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// width=device-width (or less than device-width) eliminates click delay.
|
||||
if (document.documentElement.scrollWidth <= window.outerWidth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97)
|
||||
if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Firefox version - zero for other browsers
|
||||
firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1];
|
||||
|
||||
if (firefoxVersion >= 27) {
|
||||
// Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896
|
||||
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx
|
||||
if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Factory method for creating a FastClick object
|
||||
*
|
||||
* @param {Element} layer The layer to listen on
|
||||
* @param {Object} [options={}] The options to override the defaults
|
||||
*/
|
||||
FastClick.attach = function(layer, options) {
|
||||
return new FastClick(layer, options);
|
||||
};
|
||||
|
||||
|
||||
if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
|
||||
|
||||
// AMD. Register as an anonymous module.
|
||||
define(function() {
|
||||
return FastClick;
|
||||
});
|
||||
} else if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = FastClick.attach;
|
||||
module.exports.FastClick = FastClick;
|
||||
} else {
|
||||
window.FastClick = FastClick;
|
||||
}
|
||||
}());
|
||||
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user