TinyImg 2.0.0:更名、下线 SM.MS、新增后台 Token 设置页
基于 ImgURL 1.x 的二次开发版本,主要变更:
1. 更名
- 项目定名为 TinyImg,源码中不再出现旧品牌字样(0 处)
- static/imgurl.js -> static/tinyimg.js
- db/imgurl-simple.db3 -> db/tinyimg-simple.db3
2. 移除 SM.MS 上传
- 删除 embed.js 中的 upload.render / smshow / deletesm
- miniup.html 去掉 SM.MS 选项卡;前台与后台导航移除入口
- sm.php、functions/sm.php、admin/smadmin.php 改为下线说明页
- admin/delete.php 移除 type=sm 分支;class.admin.php 删除 querysm()/deletesm()
3. 新增后台 Token 设置(admin/setting.php + functions/token.php)
- 生成 / 自定义 / 启用 / 停用 / 清空,全部校验 Session CSRF
- 存储于 db/tinyimg-token.php(首行 <?php exit; 守卫)
- config.php 的 api_token 仅作兼容回退,保存一次后由文件接管
- 完整 Token 不写入页面 HTML:默认只渲染掩码,点「显示/复制」时
经 POST action=reveal(同源 + CSRF + 仅登录会话)按需取回
4. 上传端点鉴权
- 统一使用 X-TinyImg-Token 请求头,hash_equals 比较,空配置 fail closed
- 新增 ?ping=1 自检,返回版本、鉴权方式、管理员目录,供写作插件测试连接
5. 版本号
- 统一为 v2.0.0(20261104),前后台页脚引用 functions/version.php
6. 兼容性修复
- class.upload.php 中 $size{...} 花括号下标改为 $size[...](PHP 8 已移除该语法)
7. 仓库整理
- .gitignore 排除 config.php / db/tinyimg-token.php / 运行时目录,
保留 db/.htaccess 与空模板 db/tinyimg-simple.db3
- .gitattributes 统一 LF
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* clipboard.js
|
||||
* width clipboard.js, you can copy cut and paste clipboard data
|
||||
* the main methods ard execCommand for modern browser and clipboardData for ie
|
||||
* @author [email protected]
|
||||
* @url https://github.com/baixuexiyang/clipBoard.js
|
||||
*/
|
||||
!function(t,e){"undefined"!=typeof module&&module.exports?module.exports=e():"function"==typeof define&&define.amd?define(e):this[t]=e()}("clipBoard",function(){"use strict";function t(t,e){this.options=e||{},this.tar=t[0]||t,this.options.copy&&this.copyd(),this.options.cut&&this.cut(),this.options.paste&&this.paste()}return t.prototype.copyd=function(t){if(this.options.beforeCopy&&this.options.beforeCopy(),t=t||this.tar.value||this.tar.innerText,this.options.copy&&(t=this.options.copy()),document.execCommand){var e=document.createElement("SPAN");if(e.textContent=t,document.body.appendChild(e),document.selection){var o=document.body.createTextRange();o.moveToElementText(e),o.select()}else if(window.getSelection){var o=document.createRange();o.selectNode(e),window.getSelection().removeAllRanges(),window.getSelection().addRange(o)}document.execCommand("copy"),e.remove?e.remove():e.removeNode(!0)}window.clipboardData&&window.clipboardData.setData("text",t),this.options.afterCopy&&this.options.afterCopy()},t.prototype.cut=function(){if("text"===this.tar.type||"textarea"===this.tar.type){if(this.options.beforeCut&&this.options.beforeCut(),document.execCommand){var t=this.tar;if(document.selection){var e=document.body.createTextRange();e.moveToElementText(t),e.select()}else window.getSelection&&t.select();document.execCommand("cut")}window.clipboardData&&(window.clipboardData.setData("text",this.tar.value),this.tar.value=""),this.options.afterCut&&this.options.afterCut()}},t.prototype.paste=function(){if("text"===this.tar.type||"textarea"===this.tar.type){if(this.options.beforePaste&&this.options.beforePaste(),document.execCommand){var t=this.tar;if(t.setSelectionRange)t.focus(),t.setSelectionRange(t.value.length,t.value.length);else if(t.createTextRange){var e=t.createTextRange();e.collapse(!0),e.moveEnd("character",t.value.length),e.moveStart("character",t.value.length),e.select()}document.execCommand("paste")}!document.execCommand&&window.clipboardData&&(this.tar.value+=window.clipboardData.getData("text")),this.options.afterPaste&&this.options.afterPaste()}},t});
|
||||
@@ -0,0 +1,112 @@
|
||||
'use strict';
|
||||
(function(root, factory){
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.ctrlVUtil = factory();
|
||||
}
|
||||
}(this, function(){
|
||||
function ctrlVUtil(option){
|
||||
this.targetElement = null;
|
||||
this.uploadInput = null;
|
||||
this.uploadUrl = "http://www.oa.com/screenshot/create-file";
|
||||
this.isCompleteImg = false;
|
||||
var that = this;
|
||||
that.mixinConfig(option);
|
||||
that.targetElement.addEventListener("mouseover", function() {
|
||||
that.uploadInput.focus();
|
||||
});
|
||||
that.targetElement.addEventListener("click", function() {
|
||||
that.uploadInput.focus();
|
||||
});
|
||||
that.targetElement.addEventListener("mouseleave", function() {
|
||||
that.uploadInput.blur();
|
||||
});
|
||||
that.uploadInput.addEventListener('paste', function(e) {
|
||||
that.handlePaste(e);
|
||||
});
|
||||
}
|
||||
ctrlVUtil.prototype.mixinConfig = function(option){
|
||||
this.targetElement = option.targetElement || document.querySelector(".js-upload");
|
||||
this.uploadInput = this.createInputTarget();
|
||||
this.isCompleteImg = "isCompleteImg" in option ? option.isCompleteImg : this.isCompleteImg;
|
||||
this.uploadUrl = option.uploadUrl || this.uploadUrl;
|
||||
this.data = option.data;
|
||||
this.success = option.success || function(data) {
|
||||
console.log(data);
|
||||
};
|
||||
this.error = option.error || function(error) {
|
||||
console.log(error);
|
||||
};
|
||||
};
|
||||
ctrlVUtil.prototype.createInputTarget = function() {
|
||||
var imgContinaer = document.createElement("div");
|
||||
imgContinaer.style.cssText = "border:none;margin:0;padding:0;font-size: 0;height:1px;width:1px;opacity:0;position:fixed;z-index:-1;";
|
||||
imgContinaer.contentEditable = true;
|
||||
imgContinaer.class = "ui-ctrlv-uploadInput";
|
||||
this.targetElement.parentNode.insertBefore(imgContinaer, this.targetElement);
|
||||
return imgContinaer;
|
||||
};
|
||||
ctrlVUtil.prototype.handlePaste = function(e){
|
||||
var that = this;
|
||||
if (e && e.clipboardData && e.clipboardData.items) {
|
||||
var item = e.clipboardData.items[0],
|
||||
that = this;
|
||||
if (item.type.indexOf('image') != -1) {
|
||||
var blob = item.getAsFile();
|
||||
var fileReader = new FileReader();
|
||||
fileReader.readAsDataURL(blob);
|
||||
fileReader.addEventListener('load', function(e) {
|
||||
var file = e.target.result;
|
||||
that.send(file);
|
||||
}, false);
|
||||
} else {
|
||||
layer.msg('请粘贴image类型!');
|
||||
}
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
var $img = that.uploadInput.querySelector("img");
|
||||
if ($img) {
|
||||
that.send($img.src);
|
||||
} else {
|
||||
layer.msg('当前浏览器不支持剪贴板操作!');
|
||||
return;
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
};
|
||||
ctrlVUtil.prototype.send = function(imgcontent) {
|
||||
layer.load();
|
||||
var that = this;
|
||||
that.uploadInput.innerHTML = "";
|
||||
var data = that.data || {};
|
||||
data.content = this.isCompleteImg ? imgcontent : imgcontent.split(';')[1].split(',')[1];
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("post",that.uploadUrl,true);
|
||||
xhr.onreadystatechange = function(e) {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
var ret = JSON.parse(xhr.responseText);
|
||||
that.success && that.success(ret);
|
||||
} else {
|
||||
that.error && that.error(e, xhr);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.onerror = function(e) {
|
||||
that.error && that.error(e, xhr);
|
||||
};
|
||||
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
|
||||
var dataString = [];
|
||||
for(var key in data){
|
||||
dataString.push(key+"="+encodeURIComponent(data[key]));
|
||||
}
|
||||
xhr.send(dataString.join("&"));
|
||||
};
|
||||
ctrlVUtil.prototype.alertMsg = function(content){
|
||||
alert(content);
|
||||
}
|
||||
return ctrlVUtil;
|
||||
}));
|
||||
@@ -0,0 +1,396 @@
|
||||
//layui 根目录配置
|
||||
layui.config({
|
||||
base: '/static/layui/',
|
||||
})
|
||||
//载入layui组建
|
||||
layui.use(['layer', 'form','element','upload','flow'], function(){
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var element = layui.element;
|
||||
var upload = layui.upload;
|
||||
var flow = layui.flow;
|
||||
//图片懒加载
|
||||
flow.lazyimg({
|
||||
elem:'#found-img img'
|
||||
});
|
||||
flow.lazyimg({
|
||||
elem:'#adminpic img'
|
||||
});
|
||||
//图片查看器
|
||||
layer.photos({
|
||||
photos: '#adminpic'
|
||||
,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
|
||||
});
|
||||
layer.photos({
|
||||
photos: '#found-img'
|
||||
,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
|
||||
});
|
||||
|
||||
//首页拖拽上传
|
||||
upload.render({
|
||||
elem: '#upimg'
|
||||
,url: 'functions/upload.php'
|
||||
,size: 2048 //限制上传大小为2M
|
||||
,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
|
||||
layer.load(); //上传loading
|
||||
}
|
||||
,done: function(res){
|
||||
//如果上传失败
|
||||
if(res.code == 0){
|
||||
layer.open({
|
||||
title: '温馨提示'
|
||||
,content: res.msg
|
||||
});
|
||||
layer.closeAll('loading');
|
||||
}
|
||||
else if(res.code == 1){
|
||||
layer.closeAll('loading');
|
||||
$("#showpic a").attr('href',res.url);
|
||||
$("#showpic img").attr('src',res.url);
|
||||
$("#url").val(res.url);
|
||||
$("#html").val("<img src = '" + res.url + "' />");
|
||||
$("#markdown").val("");
|
||||
$("#bbcode").val("[img]" + res.url + "[/img]");
|
||||
$("#upok").show();
|
||||
//请求接口处理图片
|
||||
$.get("./dispose.php?id="+res.id,function(data,status){
|
||||
var obj = eval('(' + data + ')');
|
||||
if(obj.level == 3){
|
||||
layer.open({
|
||||
title: '温馨提示'
|
||||
,content: '请勿上传违规图片!'
|
||||
});
|
||||
}
|
||||
if(obj.level == null){
|
||||
$.get("./dispose.php?id="+res.id,function(data,status){
|
||||
var obj = eval('(' + data + ')');
|
||||
if(obj.level == 3){
|
||||
layer.open({
|
||||
title: '温馨提示'
|
||||
,content: '请勿上传违规图片!'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// TinyImg 2.0:第三方 SM.MS 上传通道已移除,仅保留本站上传
|
||||
});
|
||||
|
||||
//复制链接
|
||||
function copy(info){
|
||||
var copy = new clipBoard(document.getElementById('piclink'), {
|
||||
beforeCopy: function() {
|
||||
info = $("#" + info).val();
|
||||
},
|
||||
copy: function() {
|
||||
return info;
|
||||
},
|
||||
afterCopy: function() {
|
||||
|
||||
}
|
||||
});
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
|
||||
layer.msg('复制成功!', {time: 2000})
|
||||
});
|
||||
}
|
||||
//后台复制URL
|
||||
function copyurl(url){
|
||||
var copy = new clipBoard(document.getElementById('adminpic'), {
|
||||
beforeCopy: function() {
|
||||
|
||||
},
|
||||
copy: function() {
|
||||
return url;
|
||||
},
|
||||
afterCopy: function() {
|
||||
|
||||
}
|
||||
});
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
|
||||
layer.msg('链接已复制!', {time: 2000})
|
||||
});
|
||||
}
|
||||
|
||||
//复制链接
|
||||
function newcopy(info){
|
||||
var copy = new clipBoard(document.getElementById('url'), {
|
||||
beforeCopy: function() {
|
||||
info = $("#" + info).val();
|
||||
},
|
||||
copy: function() {
|
||||
return info;
|
||||
},
|
||||
afterCopy: function() {
|
||||
|
||||
}
|
||||
});
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
|
||||
layer.msg('复制成功!', {time: 2000})
|
||||
});
|
||||
}
|
||||
|
||||
//用户登录方法
|
||||
function login(){
|
||||
// 获取用户提交的信息
|
||||
var user = $("#user").val();
|
||||
var password = $("#password").val();
|
||||
|
||||
if((user == '') || (password == '')){
|
||||
layer.msg('用户名或密码不能为空!');
|
||||
return false;
|
||||
}
|
||||
|
||||
$.post("../functions/Controller.php?type=login",{user:user,password:password},function(data,status){
|
||||
layer.msg(data,{time:2000});
|
||||
});
|
||||
}
|
||||
|
||||
//用户前台预览图片
|
||||
function userpreview(tinyimg,id){
|
||||
var showimg = "<center><img style = 'max-width:100%;max-height:100%;' src = '" + tinyimg + "' /></center>";
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
layer.open({
|
||||
type: 1,
|
||||
title:"图片预览",
|
||||
area: ['80%', '80%'],
|
||||
content: showimg
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//后台管理员查看图片
|
||||
function adminshow(tinyimg,id){
|
||||
$("#adminshow").show();
|
||||
$("#url").val(tinyimg);
|
||||
$("#html").val("<img src = '" + tinyimg + "' />");
|
||||
$("#markdown").val("");
|
||||
$("#bbcode").val("[img]" + tinyimg + "[/img]");
|
||||
|
||||
$("#copy").show();
|
||||
$("#adminshow img").attr("src",tinyimg);
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
layer.open({
|
||||
type: 1,
|
||||
title:false,
|
||||
area: '720px',
|
||||
content: $("#adminshow"),
|
||||
btn: ['删除'],
|
||||
cancel: function(index, layero){
|
||||
$("#adminshow img").attr("src","");
|
||||
$("#copy").hide();
|
||||
},
|
||||
yes: function(index, layero){
|
||||
layer.confirm('确认删除?', {icon: 3, title:'温馨提示!'}, function(index){
|
||||
$.get("./delete.php?id="+id,function(data,status){
|
||||
if(data == 'ok') {
|
||||
|
||||
$("#imgid"+id).remove();
|
||||
$("#adminshow img").attr("src","");
|
||||
$("#copy").hide();
|
||||
}
|
||||
else{
|
||||
alert(data);
|
||||
}
|
||||
});
|
||||
|
||||
layer.closeAll();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//删除某张图片
|
||||
function deleteimg(id){
|
||||
layer.confirm('确认删除?', {icon: 3, title:'温馨提示!'}, function(index){
|
||||
$.get("./delete.php?id="+id,function(data,status){
|
||||
if(data == 'ok') {
|
||||
$("#imgid"+id).remove();
|
||||
}
|
||||
else{
|
||||
alert(data);
|
||||
}
|
||||
});
|
||||
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
//取消图片可疑状态
|
||||
function cdubious(id){
|
||||
layer.confirm('确认取消图片可疑状态?', {icon: 3, title:'温馨提示!'}, function(index){
|
||||
$.get("./operation.php?type=cdubious&id="+id,function(data,status){
|
||||
if(data == 'ok') {
|
||||
$("#imgid"+id).remove();
|
||||
}
|
||||
else{
|
||||
alert(data);
|
||||
}
|
||||
});
|
||||
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
|
||||
//图片压缩功能
|
||||
function compress(id){
|
||||
//layer.msg('该功能还在开发中!', {time: 2000})
|
||||
layer.open({
|
||||
type:3
|
||||
,content: '处理中...'
|
||||
});
|
||||
$.get("../functions/class/class.pic.php?id=" + id,function(data,status){
|
||||
if(status == 'success'){
|
||||
layer.closeAll('loading');
|
||||
}
|
||||
layer.open({
|
||||
title: '温馨提示:',
|
||||
time:2000
|
||||
,content: data
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//IP查询
|
||||
function ipquery(ip){
|
||||
$.get("https://ip.awk.sh/api.php?data=addr&ip=" + ip,function(data,status){
|
||||
if(status == 'success') {
|
||||
layer.open({
|
||||
title: 'IP查询结果:'
|
||||
,content: data
|
||||
,time:3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//关于
|
||||
function about(){
|
||||
url = window.location.protocol + '//';
|
||||
url = url + window.location.host + '/';
|
||||
layer.open({
|
||||
title: '关于',
|
||||
type: 2,
|
||||
area: ['240px', '100px'],
|
||||
content: "./about.php"
|
||||
});
|
||||
}
|
||||
|
||||
//删除本页所有照片
|
||||
function delall(){
|
||||
layer.confirm('确认删除本页所有图片?', {icon: 3, title:'提示'}, function(index){
|
||||
//do something
|
||||
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
|
||||
//预览图片
|
||||
function previewimg(id,url){
|
||||
var imgid = "img" + id;
|
||||
var upid = id - 1;
|
||||
|
||||
var dnid = id + 1;
|
||||
|
||||
$("#show" + upid).hide();
|
||||
$("#show" + dnid).hide();
|
||||
|
||||
$("#img" + id).attr('src',url);
|
||||
$("#show" + id).show();
|
||||
|
||||
}
|
||||
//隐藏图片
|
||||
function hideimg(id){
|
||||
var upid = id - 1;
|
||||
|
||||
var dnid = id + 1;
|
||||
$("#show" + id).hide();
|
||||
$("#show" + upid).hide();
|
||||
$("#show" + dnid).hide();
|
||||
}
|
||||
|
||||
//Ctrl + V上传图片
|
||||
//$(document).keyup(function(){
|
||||
// if(event.keyCode == 86){
|
||||
|
||||
// }
|
||||
//});
|
||||
|
||||
//预览图片
|
||||
function viewimg(id,tinyimg){
|
||||
id = "viewimg" + id;
|
||||
$("#" + id + " img").attr('src',tinyimg);
|
||||
//显示图片
|
||||
$("#" + id).show();
|
||||
|
||||
}
|
||||
//隐藏图片
|
||||
function hideimg(id){
|
||||
id = "viewimg" + id;
|
||||
$("#" + id).hide();
|
||||
}
|
||||
|
||||
//URL上传
|
||||
function urlup(){
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
layer.open({
|
||||
type:3
|
||||
,content: '上传中,请等待...'
|
||||
});
|
||||
});
|
||||
arr = $("#arrurl").val();
|
||||
//如果地址为空
|
||||
if(arr == ''){
|
||||
layer.closeAll('loading');
|
||||
layer.msg('地址不能为空!');
|
||||
return false;
|
||||
}
|
||||
|
||||
$.post("../functions/urlup.php",{arr:arr},function(data,status){
|
||||
var re = eval('(' + data + ')');
|
||||
if(re.code == 1){
|
||||
//关闭加载层
|
||||
layer.closeAll('loading');
|
||||
layer.msg(re.msg);
|
||||
}
|
||||
else if(re.code == 0){
|
||||
//关闭加载层
|
||||
layer.closeAll('loading');
|
||||
layer.msg(re.msg);
|
||||
}
|
||||
else{
|
||||
layer.closeAll('loading');
|
||||
layer.msg(re.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//时间筛选
|
||||
function screen(page){
|
||||
var starttime = $("#starttime").val();
|
||||
var endtime = $("#endtime").val();
|
||||
|
||||
if((starttime == '') || (endtime == '')){
|
||||
layui.use('layer', function(){
|
||||
var layer = layui.layer;
|
||||
layer.msg('请选择时间!');
|
||||
});
|
||||
}
|
||||
|
||||
else{
|
||||
window.location.href = page + "?page=1&date=" + starttime + '|' + endtime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
/*!
|
||||
*
|
||||
* @author: diandian & alanzhang
|
||||
* @date: 2016/8/19
|
||||
* @overview: [截屏后,按粘贴快捷键ctrl+v上传,]
|
||||
* @兼容性说明: IE11,Firefox,chrome
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
(function(root, factory){
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD
|
||||
define([], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node, CommonJS-like
|
||||
module.exports = factory();
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.ctrlVUtil = factory();
|
||||
}
|
||||
}(this, function(){
|
||||
|
||||
function ctrlVUtil(option){
|
||||
|
||||
// 鼠标在该元素上,使用ctrl+v键时上传
|
||||
this.targetElement = null;
|
||||
|
||||
// 用于响应paste事件的元素,如果页面不传递,则创建该元素,并位于targetElement前面
|
||||
this.uploadInput = null;
|
||||
|
||||
// 默认的上传地址
|
||||
this.uploadUrl = "http://www.oa.com/screenshot/create-file";
|
||||
|
||||
// 对于读取的图片base64,前缀为data:image/jpg;base64,base64content
|
||||
// isCompleteImg为false则去掉前缀直接上传内容部分,为true则上传完整的base64字符串
|
||||
this.isCompleteImg = false;
|
||||
|
||||
var that = this;
|
||||
|
||||
// 合并参数
|
||||
that.mixinConfig(option);
|
||||
|
||||
// 鼠标移入和点击时上传,移出时失焦
|
||||
that.targetElement.addEventListener("mouseover", function() {
|
||||
that.uploadInput.focus();
|
||||
});
|
||||
|
||||
that.targetElement.addEventListener("click", function() {
|
||||
that.uploadInput.focus();
|
||||
});
|
||||
|
||||
// 移除鼠标则input失去交掉
|
||||
that.targetElement.addEventListener("mouseleave", function() {
|
||||
that.uploadInput.blur();
|
||||
});
|
||||
|
||||
// 监听paste的事件
|
||||
that.uploadInput.addEventListener('paste', function(e) {
|
||||
that.handlePaste(e);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [mixinConfig 整合参数]
|
||||
* @param {[type]} option [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
ctrlVUtil.prototype.mixinConfig = function(option){
|
||||
this.targetElement = option.targetElement || document.querySelector(".js-upload");
|
||||
this.uploadInput = this.createInputTarget();
|
||||
|
||||
this.isCompleteImg = "isCompleteImg" in option ? option.isCompleteImg : this.isCompleteImg;
|
||||
|
||||
// 上传地址
|
||||
this.uploadUrl = option.uploadUrl || this.uploadUrl;
|
||||
|
||||
// 除了图片内容以外的其他数据
|
||||
this.data = option.data;
|
||||
|
||||
// 上传成功时的回调函数
|
||||
this.success = option.success || function(data) {
|
||||
console.log(data);
|
||||
};
|
||||
|
||||
// 上传失败时的回调函数
|
||||
this.error = option.error || function(error) {
|
||||
console.log(error);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* [createInputTarget 创建div元素,用于响应paste事件]
|
||||
* @return {Element} [description]
|
||||
*/
|
||||
ctrlVUtil.prototype.createInputTarget = function() {
|
||||
var imgContinaer = document.createElement("div");
|
||||
|
||||
// 使其不可见
|
||||
imgContinaer.style.cssText = "border:none;margin:0;padding:0;font-size: 0;height:1px;width:1px;opacity:0;position:fixed;z-index:-1;";
|
||||
|
||||
// 让其可编辑,能响应paste事件
|
||||
imgContinaer.contentEditable = true;
|
||||
imgContinaer.class = "ui-ctrlv-uploadInput";
|
||||
|
||||
// 插入targeElementn前面
|
||||
this.targetElement.parentNode.insertBefore(imgContinaer, this.targetElement);
|
||||
|
||||
return imgContinaer;
|
||||
};
|
||||
|
||||
/**
|
||||
* [handlePaste 处理粘贴行为]
|
||||
* @param {Event} e [粘贴事件]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
ctrlVUtil.prototype.handlePaste = function(e){
|
||||
|
||||
var that = this;
|
||||
|
||||
// webkit 内核支持items方法
|
||||
if (e && e.clipboardData && e.clipboardData.items) {
|
||||
|
||||
// 获取item
|
||||
var item = e.clipboardData.items[0],
|
||||
that = this;
|
||||
|
||||
if (item.type.indexOf('image') != -1) {
|
||||
|
||||
var blob = item.getAsFile();
|
||||
|
||||
// 创建读取对象
|
||||
var fileReader = new FileReader();
|
||||
|
||||
// 将文件读取为字符串
|
||||
fileReader.readAsDataURL(blob);
|
||||
|
||||
fileReader.addEventListener('load', function(e) {
|
||||
var file = e.target.result;
|
||||
that.send(file);
|
||||
}, false);
|
||||
|
||||
} else {
|
||||
//that.alertMsg("请粘贴image类型");
|
||||
layer.msg('请粘贴image类型!');
|
||||
}
|
||||
|
||||
// firefox无法使用items方法,在粘贴时,图片会作为img标签插入targetElement中,
|
||||
// 获取img标签的src内容进行上传
|
||||
} else {
|
||||
|
||||
setTimeout(function() {
|
||||
var $img = that.uploadInput.querySelector("img");
|
||||
|
||||
if ($img) {
|
||||
that.send($img.src);
|
||||
} else {
|
||||
//that.alertMsg("浏览器不支持剪贴板操作");
|
||||
layer.msg('当前浏览器不支持剪贴板操作!');
|
||||
return;
|
||||
}
|
||||
|
||||
}, 200);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* [send 上传图片]
|
||||
* @param {string} imgcontent [图片内容base64格式]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
ctrlVUtil.prototype.send = function(imgcontent) {
|
||||
//自己添加的,显示上传加载
|
||||
layer.load();
|
||||
|
||||
var that = this;
|
||||
|
||||
that.uploadInput.innerHTML = "";
|
||||
|
||||
var data = that.data || {};
|
||||
|
||||
// 根据sCompleteImg来决定上传的是整体的base64字符串还是仅仅为内容部分
|
||||
data.content = this.isCompleteImg ? imgcontent : imgcontent.split(';')[1].split(',')[1];
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open("post",that.uploadUrl,true);
|
||||
|
||||
xhr.onreadystatechange = function(e) {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200) {
|
||||
var ret = JSON.parse(xhr.responseText);
|
||||
that.success && that.success(ret);
|
||||
} else {
|
||||
that.error && that.error(e, xhr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function(e) {
|
||||
that.error && that.error(e, xhr);
|
||||
};
|
||||
|
||||
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
|
||||
|
||||
var dataString = [];
|
||||
|
||||
for(var key in data){
|
||||
dataString.push(key+"="+encodeURIComponent(data[key]));
|
||||
}
|
||||
|
||||
xhr.send(dataString.join("&"));
|
||||
};
|
||||
|
||||
ctrlVUtil.prototype.alertMsg = function(content){
|
||||
alert(content);
|
||||
}
|
||||
|
||||
// 暴露构造函数
|
||||
return ctrlVUtil;
|
||||
}));
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/** layui-v2.2.6 MIT License By https://www.layui.com */
|
||||
html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #e2e2e2;border-left-width:6px;background-color:#F2F2F2;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:32px;line-height:32px;border-bottom:1px solid #e2e2e2}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 5px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}
|
||||
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 701 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 269 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 6.6 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 777 B |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,2 @@
|
||||
/** layui-v2.2.6 MIT License By https://www.layui.com */
|
||||
;layui.define("jquery",function(e){"use strict";var i=layui.$,n=(layui.hint(),layui.device(),{config:{},set:function(e){var n=this;return n.config=i.extend({},n.config,e),n},on:function(e,i){return layui.onevent.call(this,t,e,i)}}),t="carousel",a="layui-this",l=">*[carousel-item]>*",o="layui-carousel-left",r="layui-carousel-right",d="layui-carousel-prev",s="layui-carousel-next",u="layui-carousel-arrow",c="layui-carousel-ind",m=function(e){var t=this;t.config=i.extend({},t.config,n.config,e),t.render()};m.prototype.config={width:"600px",height:"280px",full:!1,arrow:"hover",indicator:"inside",autoplay:!0,interval:3e3,anim:"",trigger:"click",index:0},m.prototype.render=function(){var e=this,n=e.config;n.elem=i(n.elem),n.elem[0]&&(e.elemItem=n.elem.find(l),n.index<0&&(n.index=0),n.index>=e.elemItem.length&&(n.index=e.elemItem.length-1),n.interval<800&&(n.interval=800),n.full?n.elem.css({position:"fixed",width:"100%",height:"100%",zIndex:9999}):n.elem.css({width:n.width,height:n.height}),n.elem.attr("lay-anim",n.anim),e.elemItem.eq(n.index).addClass(a),e.elemItem.length<=1||(e.indicator(),e.arrow(),e.autoplay(),e.events()))},m.prototype.reload=function(e){var n=this;clearInterval(n.timer),n.config=i.extend({},n.config,e),n.render()},m.prototype.prevIndex=function(){var e=this,i=e.config,n=i.index-1;return n<0&&(n=e.elemItem.length-1),n},m.prototype.nextIndex=function(){var e=this,i=e.config,n=i.index+1;return n>=e.elemItem.length&&(n=0),n},m.prototype.addIndex=function(e){var i=this,n=i.config;e=e||1,n.index=n.index+e,n.index>=i.elemItem.length&&(n.index=0)},m.prototype.subIndex=function(e){var i=this,n=i.config;e=e||1,n.index=n.index-e,n.index<0&&(n.index=i.elemItem.length-1)},m.prototype.autoplay=function(){var e=this,i=e.config;i.autoplay&&(e.timer=setInterval(function(){e.slide()},i.interval))},m.prototype.arrow=function(){var e=this,n=e.config,t=i(['<button class="layui-icon '+u+'" lay-type="sub">'+("updown"===n.anim?"":"")+"</button>",'<button class="layui-icon '+u+'" lay-type="add">'+("updown"===n.anim?"":"")+"</button>"].join(""));n.elem.attr("lay-arrow",n.arrow),n.elem.find("."+u)[0]&&n.elem.find("."+u).remove(),n.elem.append(t),t.on("click",function(){var n=i(this),t=n.attr("lay-type");e.slide(t)})},m.prototype.indicator=function(){var e=this,n=e.config,t=e.elemInd=i(['<div class="'+c+'"><ul>',function(){var i=[];return layui.each(e.elemItem,function(e){i.push("<li"+(n.index===e?' class="layui-this"':"")+"></li>")}),i.join("")}(),"</ul></div>"].join(""));n.elem.attr("lay-indicator",n.indicator),n.elem.find("."+c)[0]&&n.elem.find("."+c).remove(),n.elem.append(t),"updown"===n.anim&&t.css("margin-top",-(t.height()/2)),t.find("li").on("hover"===n.trigger?"mouseover":n.trigger,function(){var t=i(this),a=t.index();a>n.index?e.slide("add",a-n.index):a<n.index&&e.slide("sub",n.index-a)})},m.prototype.slide=function(e,i){var n=this,l=n.elemItem,u=n.config,c=u.index,m=u.elem.attr("lay-filter");n.haveSlide||("sub"===e?(n.subIndex(i),l.eq(u.index).addClass(d),setTimeout(function(){l.eq(c).addClass(r),l.eq(u.index).addClass(r)},50)):(n.addIndex(i),l.eq(u.index).addClass(s),setTimeout(function(){l.eq(c).addClass(o),l.eq(u.index).addClass(o)},50)),setTimeout(function(){l.removeClass(a+" "+d+" "+s+" "+o+" "+r),l.eq(u.index).addClass(a),n.haveSlide=!1},300),n.elemInd.find("li").eq(u.index).addClass(a).siblings().removeClass(a),n.haveSlide=!0,layui.event.call(this,t,"change("+m+")",{index:u.index,prevIndex:c,item:l.eq(u.index)}))},m.prototype.events=function(){var e=this,i=e.config;i.elem.data("haveEvents")||(i.elem.on("mouseenter",function(){clearInterval(e.timer)}).on("mouseleave",function(){e.autoplay()}),i.elem.data("haveEvents",!0))},n.render=function(e){var i=new m(e);return i},e(t,n)});
|
||||
@@ -0,0 +1,2 @@
|
||||
/** layui-v2.2.6 MIT License By https://www.layui.com */
|
||||
;layui.define("jquery",function(e){"use strict";var a=layui.$,l="http://www.layui.com/doc/modules/code.html";e("code",function(e){var t=[];e=e||{},e.elem=a(e.elem||".layui-code"),e.about=!("about"in e)||e.about,e.elem.each(function(){t.push(this)}),layui.each(t.reverse(),function(t,i){var c=a(i),o=c.html();(c.attr("lay-encode")||e.encode)&&(o=o.replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""")),c.html('<ol class="layui-code-ol"><li>'+o.replace(/[\r\t\n]+/g,"</li><li>")+"</li></ol>"),c.find(">.layui-code-h3")[0]||c.prepend('<h3 class="layui-code-h3">'+(c.attr("lay-title")||e.title||"code")+(e.about?'<a href="'+l+'" target="_blank">layui.code</a>':"")+"</h3>");var d=c.find(">.layui-code-ol");c.addClass("layui-box layui-code-view"),(c.attr("lay-skin")||e.skin)&&c.addClass("layui-code-"+(c.attr("lay-skin")||e.skin)),(d.find("li").length/100|0)>0&&d.css("margin-left",(d.find("li").length/100|0)+"px"),(c.attr("lay-height")||e.height)&&d.css("max-height",c.attr("lay-height")||e.height)})})}).addcss("modules/code.css","skincodecss");
|
||||
@@ -0,0 +1,2 @@
|
||||
/** layui-v2.2.6 MIT License By https://www.layui.com */
|
||||
;layui.define("jquery",function(e){"use strict";var l=layui.$,o=function(e){},t='<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon "></i>';o.prototype.load=function(e){var o,i,n,r,a=this,c=0;e=e||{};var f=l(e.elem);if(f[0]){var m=l(e.scrollElem||document),u=e.mb||50,s=!("isAuto"in e)||e.isAuto,v=e.end||"没有更多了",y=e.scrollElem&&e.scrollElem!==document,d="<cite>加载更多</cite>",h=l('<div class="layui-flow-more"><a href="javascript:;">'+d+"</a></div>");f.find(".layui-flow-more")[0]||f.append(h);var p=function(e,t){e=l(e),h.before(e),t=0==t||null,t?h.html(v):h.find("a").html(d),i=t,o=null,n&&n()},g=function(){o=!0,h.find("a").html(t),"function"==typeof e.done&&e.done(++c,p)};if(g(),h.find("a").on("click",function(){l(this);i||o||g()}),e.isLazyimg)var n=a.lazyimg({elem:e.elem+" img",scrollElem:e.scrollElem});return s?(m.on("scroll",function(){var e=l(this),t=e.scrollTop();r&&clearTimeout(r),i||(r=setTimeout(function(){var i=y?e.height():l(window).height(),n=y?e.prop("scrollHeight"):document.documentElement.scrollHeight;n-t-i<=u&&(o||g())},100))}),a):a}},o.prototype.lazyimg=function(e){var o,t=this,i=0;e=e||{};var n=l(e.scrollElem||document),r=e.elem||"img",a=e.scrollElem&&e.scrollElem!==document,c=function(e,l){var o=n.scrollTop(),r=o+l,c=a?function(){return e.offset().top-n.offset().top+o}():e.offset().top;if(c>=o&&c<=r&& e.attr("lay-src")){var m=e.attr("lay-src");layui.img(m,function(){var l=t.lazyimg.elem.eq(i);e.attr("src",m).removeAttr("lay-src"),l[0]&&f(l),i++})}},f=function(e,o){var f=a?(o||n).height():l(window).height(),m=n.scrollTop(),u=m+f;if(t.lazyimg.elem=l(r),e)c(e,f);else for(var s=0;s<t.lazyimg.elem.length;s++){var v=t.lazyimg.elem.eq(s),y=a?function(){return v.offset().top-n.offset().top+m}():v.offset().top;if(c(v,f),i=s,y>u)break}};if(f(),!o){var m;n.on("scroll",function(){var e=l(this);m&&clearTimeout(m),m=setTimeout(function(){f(null,e)},50)}),o=!0}return f},e("flow",new o)});
|
||||