新增页面

有登陆过滤器
正式上线1.0
This commit is contained in:
2020-05-04 03:26:52 +08:00
parent 6cb1c0f9eb
commit 6627f00d3e
41 changed files with 6561 additions and 129 deletions

View File

@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>NAS</title>
<link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
<div id="header"></div>
<div class="layui-body" style="left: 200px;">
<div id="side"></div>
<blockquote class="layui-elem-quote"><span id="ip">B站直播下载器</span></blockquote>
<table id="address" lay-filter="listTools"></table>
<div id="footer"></div>
</div>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script type="text/html" id="listTools">
<a class="layui-btn layui-btn-xs" lay-event="set">设置</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code != 0) {
window.location.href = "/"
}
})
layui.use(['layer', 'form', 'element', 'table'], function () {
var layer = layui.layer
, form = layui.form
, table = layui.table;
table.render({
elem: "#address"
, url: '/bili/live/get/url.do'
, page: true
, cols: [[
{ field: "id", title: "id", width: 80, sort: true, fixed: 'left' }
, { field: 'cid', title: 'cid', width: 100 }
, { field: 'url', title: 'url', width: 400 }
, { field: 'status', title: '状态', width: 80 }
, { field: "right", width: 200, toolbar: '#listTools' }
]]
});
table.on('tool(listTools)', function (obj) {
let data = obj.data;
if (obj.event === 'set') {
layer.open({
title: '设置'
, content: '切换状态'
, btn: ['启动', '关闭']
, yes: function (index, obj) {
$.post('/bili/live/set/update.do', { id: data.id, status: '1' }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg);
table.reload('address')
})
layer.close(index)
},
btn2: function (index, obj) {
$.post('/bili/live/set/update.do', { id: data.id, status: '0' }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg);
table.reload('address')
})
table.reload('address')
layer.close(index)
}
})
} else if (obj.event === 'edit') {
layer.prompt({
title: "请输入链接或cid"
}, function (value, index) {
$.post('/bili/live/set/update.do', { id: data.id, url: value }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg);
table.reload('address')
})
table.reload('address')
layer.close(index)
})
} else {
layer.open({
title: "删除提示"
, content: "确认删除?"
, btn: ['确认', '取消']
, yes: function (index, layero) {
$.post('bili/live/set/delete.do', { id: data.id }, function () {
table.reload('address')
});
layer.close(index)
},
btn2: function (index, layero) {
layer.close(index)
}
})
}
})
});
$.ajax({ cache: false })
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
</script>
<style>
#icon {
float: right;
}
.body {
bottom: 0;
}
</style>
</body>
</html>

View File

@@ -30,12 +30,17 @@
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code != 0) {
window.location.href = "/"
}
})
</script>
<style>
#icon {
#icon {
float: right;
}
.body {
bottom: 0;
}

View File

@@ -13,14 +13,19 @@
<div id="header"></div>
<div class="layui-body" style="left: 200px;">
<div id="side"></div>
<blockquote class="layui-elem-quote" ><span id="ip">当前IP:</span></blockquote>
<blockquote class="layui-elem-quote"><span id="ip">当前IP:</span></blockquote>
<div id="footer"></div>
</div>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script>
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code != 0) {
window.location.href = "/"
}
})
layui.use(['layer', 'form', 'element'], function () {
var layer = layui.layer
, form = layui.form;
@@ -30,20 +35,26 @@
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
$.post("/nas/getIp.do",function(data){
var json=JSON.parse(data);
if(json.code!=0){
$.post("/nas/getIp.do", function (data) {
try {
var json = JSON.parse(data);
} catch (error) {
window.location.href = "/"
return
}
if (json.code != 0) {
$('#ip').html(json.msg);
}else{
$('#ip').html("当前服务器IP:"+json.data);
} else {
$('#ip').html("当前服务器IP:" + json.data);
}
})
</script>
<style>
#icon {
#icon {
float: right;
}
.body {
bottom: 0;
}

View File

@@ -1,7 +1,7 @@
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll layui-bg-blue">
<div class="layui-side layui-bg-black" id='myside'>
<div class="layui-side-scroll layui-bg-blue" id="myside_div">
<!-- 左侧导航区域可配合layui已有的垂直导航 -->
<ul class="layui-nav layui-nav-tree layui-bg-blue" lay-filter="test">
<ul class="layui-nav layui-nav-tree layui-bg-blue" lay-filter="test" >
<li class="layui-nav-item">
<a class="" href="javascript:;">本体管理</a>
<dl class="layui-nav-child">
@@ -9,20 +9,30 @@
</dl>
</li>
<li class="layui-nav-item">
<a class="" href="javascript:;">管理后台</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;">切换管理后台</a></dd>
<dd><a href="javascript:;">管理后台</a></dd>
<dd><a href="javascript:;">Jellyfin</a></dd>
</dl>
<a class="" href="/html/body/nas/switchAdmin.html">管理后台</a>
</li>
<li class="layui-nav-item">
<a href="javascript:;">功能管理</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;">B站直播下载器</a></dd>
<dd><a href="/html/body/nas/bilidown.html">B站直播下载器</a></dd>
</dl>
</li>
</ul>
</div>
</div>
<script>
$(document).ready(function () {
let mobile = navigator.userAgent.toLowerCase().match(/android/i) == "android" || navigator.userAgent.toLowerCase().match(/iphone os/i) == "iphone os";
if (mobile) {
$('#myside').removeClass('layui-side')
$('#myside_div').removeClass('layui-side-scroll')
$('#myside').addClass('layui-header')
$('#myside').css('height','100%')
</div>
} else {
$('#myside').removeClass('layui-header')
$('#myside').addClass('layui-side')
$('#myside_div').addClass('layui-side-scroll')
}
})
</script>

View File

@@ -13,37 +13,138 @@
<div id="header"></div>
<div class="layui-body" style="left: 200px;">
<div id="side"></div>
<blockquote class="layui-elem-quote" ><span id="ip">当前IP:</span></blockquote>
<blockquote class="layui-elem-quote"><span id="ip">当前状态:</span></blockquote>
<div style="margin-left: 10px;">
<button type="button" id='add' class="layui-btn layui-btn-normal">新增</button>
<div style="width: 30%; margin-top: 10px; display: none;" id="adddata">
<form class="layui-form" action="">
<input type="text" name="title" id="title" required lay-verify="required" placeholder="请输入标题"
autocomplete="off" class="layui-input">
<input type="text" name="url" id="url" required lay-verify="required" placeholder="请输入URL"
autocomplete="off" class="layui-input" style="margin-top: 10px;">
<input type="number" name="port" id="port" required lay-verify="required" placeholder="请输入端口"
autocomplete="off" class="layui-input" style="margin-top: 10px;">
<div class="layui-form-item">
<button class="layui-btn" lay-submit lay-filter="formDemo"
style="margin-top: 10px;">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary"
style="margin-top: 10px;">重置</button>
</div>
</form>
</div>
<table id="address" lay-filter="listTools"></table>
</div>
<div id="footer"></div>
</div>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script>
layui.use(['layer', 'form', 'element'], function () {
<script type="text/html" id="listTools">
<a class="layui-btn layui-btn-xs" lay-event="set">设置</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code != 0) {
window.location.href = "/"
}
})
let editModel = 'edit';
let dataId = -1;
layui.use(['layer', 'form', 'element', 'table'], function () {
var layer = layui.layer
, form = layui.form;
, form = layui.form
, table = layui.table;
table.render({
elem: "#address"
, url: '/auth/nas/address/list.do'
, page: true
, cols: [[
{ field: "id", title: "id", width: 80, sort: true, fixed: 'left' }
, { field: 'title', title: '标题', width: 80 }
, { field: 'url', title: 'url', width: 400 }
, { field: 'port', title: '端口', width: 80 }
, { field: "right", width: 200, toolbar: '#listTools' }
]]
});
table.on('tool(listTools)', function (obj) {
let data = obj.data;
if (obj.event === 'set') {
$.post('/auth/nas/address/set.do', { id: data.id }, function (deta) {
let json = JSON.parse(deta);
layer.msg(json.msg)
setTimeout(function () {
table.reload('address')
}, 2000)
});
} else if (obj.event === 'edit') {
editModel = 'update';
dataId = data.id;
$('#title').val(data.title)
$('#url').val(data.url)
$('#port').val(data.port)
$('#adddata').css('display', '')
} else {
layer.open({
title: "删除提示"
, content: "确认删除?"
, btn: ['确认', '取消']
, yes: function (index, layero) {
$.post('/auth/nas/address/remove.do', { id: data.id }, function () {
table.reload('address')
});
layer.close(index)
},
btn2: function (index, layero) {
layer.close(index)
}
})
}
});
form.on('submit(formDemo)', function (data) {
//layer.msg(JSON.stringify(data.field));
$('#adddata').css("display", 'none')
let url = '/auth/nas/address/add.do'
if (editModel === 'update') {
url = '/auth/nas/address/update.do'
}
$.post(url, { title: data.field.title, url: data.field.url, port: data.field.port, id: dataId }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg)
table.reload('address')
});
return false;
});
});
$.ajax({ cache: false })
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
$.post("/nas/getIp.do",function(data){
var json=JSON.parse(data);
if(json.code!=0){
$.get("/auth/nas/address/get.do", function (data) {
var json = JSON.parse(data);
if (json.code != 0) {
$('#ip').html(json.msg);
} else {
$('#ip').html(json.msg);
}else{
$('#ip').html("当前服务器IP:"+json.data);
}
})
$('#add').click(function () {
editModel = 'edit'
$('#adddata').css("display", '')
})
</script>
<style>
#icon {
#icon {
float: right;
}
.body {
bottom: 0;
}

View File

@@ -0,0 +1,281 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>NAS</title>
<link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
<div id="header"></div>
<div class="layui-body" style="top: 100px; ">
<!-- <div id="side"></div> -->
<blockquote class="layui-elem-quote"><span id="ip">密码管理器</span></blockquote>
<button type="button" id="addType" class="layui-btn layui-btn-normal">新增分类</button>
<div class="layui-tab" lay-filter="type" lay-allowclose="true">
<ul class="layui-tab-title">
</ul>
<div class="layui-tab-content">
</div>
</div>
<iframe src="../../randompassword/index.html" style="width: 100%; height: 120%; " frameborder="0"
scrolling="no"></iframe>
<div id="footer"></div>
</div>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script type="text/html" id="topTools">
<a class="layui-btn layui-btn-xs" lay-event="addAddress">新增账号</a>
</script>
<script type="text/html" id="listTools">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code != 0) {
window.location.href = "/"
}
})
let tabid = -1;
layui.use(['layer', 'form', 'element', 'table'], function () {
var layer = layui.layer
, form = layui.form
, table = layui.table
, element = layui.element;
$.get("/tools/password/type/get/list.do", function (data) {
let json = JSON.parse(data);
if (json.code == 0) {
for (let index = 0; index < json.data.length; index++) {
const ret = json.data[index];
element.tabAdd('type', {
title: ret.title
, content: '<table id="passwordlist' + ret.id + '" lay-filter="listTools"></table>'
, id: ret.id
})
}
element.tabChange('type', '1');
}
});
form.render()
element.on('tab(type)', function (data) {
console.log(this)
tabid = $(this).attr('lay-id')
table.render({
elem: "#passwordlist" + tabid
, url: '/tools/password/get/list.do?type=' + tabid
, toolbar: '#topTools'
, page: true
, cols: [[
{ field: "id", title: "id", width: 80, sort: true, fixed: 'left' }
, { field: 'title', title: '标题', width: 80 }
, { field: 'username', title: '账号', width: 200 }
, { field: 'password', title: '密码', width: 200 }
, { field: 'url', title: '网址', width: 400, templet: '<div><a href="{{d.url}}" target="_blank">{{d.url}}</a></div>' }
, { field: 'info', title: '备注', width: 200 }
, { field: "right", width: 200, toolbar: '#listTools' }
]]
});
})
element.on('tabDelete(type)', function (data) {
let name = $(data.elem.prevObject.prevObject[0]).text().replace("ဆ", "")
let id = $(data.elem.prevObject.prevObject[0]).attr('lay-id')
layer.open({
title: "警告"
, content: "确认删除 " + name
, btn: ['确认', '取消']
, yes: function (index) {
$.post('/tools/password/type/set/remove.do', { id: id }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg);
})
layer.close(index)
}
, btn2: function (index) {
layer.close(index)
}
})
});
table.on('rowDouble(listTools)', function (data) {
$.get('/tools/password/get/password.do?id=' + data.data.id, function (udata) {
let json = JSON.parse(udata);
data.data.password = json.data;
data.update(data.data)
})
})
table.on('tool(listTools)', function (obj) {
if (obj.event === 'edit') {
$.get('/tools/password/get/password.do?id=' + obj.data.id, function (udata) {
let json = JSON.parse(udata);
layer.open({
title: "添加账号",
type: 1,
content: $('#adduser'),
btn: ['提交', '关闭'],
yes: function (index) {
$.post('/tools/password/set/update.do', {
title: $('#title').val()
, username: $('#username').val(), password: $('#password').val()
, url: $('#url').val(), info: $('#info').val()
, type: tabid
, id: obj.data.id
}, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg)
table.reload('passwordlist' + obj.data.id)
$('#title').val('')
$('#username').val('')
$('#password').val('')
$('#url').val('')
$('#info').val('')
layer.close(index)
})
},
btn2: function (index) {
layer.msg(tabid)
layer.close(index)
},
success: function (layero, index) {
$('#title').val(obj.data.title)
$('#username').val(obj.data.username)
$('#password').val(json.data)
$('#url').val(obj.data.url)
$('#info').val(obj.data.info)
}
})
})
} else if (obj.event === 'del') {
layer.open({
title: "警告!"
, content: "删除操作无法回滚,是否确认删除:" + obj.data.title
, btn: ['确认', '取消']
, yes: function (index) {
$.post('/tools/password/set/remove.do', { id: obj.data.id }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg)
})
},
btn2: function (index) {
layer.close(index);
}
})
}
})
table.on('toolbar(listTools)', function (obj) {
if (obj.event === 'addAddress') {
layer.open({
title: "添加账号",
type: 1,
content: $('#adduser'),
btn: ['提交', '关闭'],
yes: function (index) {
$.post('/tools/password/set/add.do', {
title: $('#title').val()
, username: $('#username').val(), password: $('#password').val()
, url: $('#url').val(), info: $('#info').val()
, type: tabid
}, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg)
table.reload('passwordlist' + tabid)
$('#title').val('')
$('#username').val('')
$('#password').val('')
$('#url').val('')
$('#info').val('')
layer.close(index)
})
},
btn2: function (index) {
layer.msg(tabid)
layer.close(index)
}
})
}
})
$('#addType').click(function () {
layer.prompt({
title: '新增分类'
}, function (value, index, elem) {
$.post('/tools/password/type/set/add.do', { type: value }, function (data) {
window.location.reload()
})
layer.close(index)
})
})
});
$.ajax({ cache: false })
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
</script>
<style>
</style>
<div style="display: none; margin: 20px;" id="adduser">
<form class="layui-form" action="">
<div class="layui-form-item">
<label class="layui-form-label">标题</label>
<div class="layui-input-block">
<input type="text" id="title" required lay-verify="required" placeholder="请输入标题"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">账号</label>
<div class="layui-input-block">
<input type="text" id="username" required lay-verify="required" placeholder="请输入账号"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="text" id="password" required lay-verify="required" placeholder="请输入密码"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">网址</label>
<div class="layui-input-block">
<input type="text" id="url" required lay-verify="required" placeholder="请输入网址URL"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">备注信息</label>
<div class="layui-input-block">
<textarea type="text" id="info" name="" required lay-verify="required" class="layui-textarea"
placeholder="请输入备注信息"></textarea>
</div>
</div>
</form>
</div>
</body>
<style>
#icon {
float: right;
}
</style>
</html>

View File

@@ -12,13 +12,13 @@
<li class="layui-nav-item"><a href="http://blog.yutou233.cn">博客</a></li>
<div id="admin" style="display: inline-block; font-size: 0px;">
<li class="layui-nav-item"><a href="/html/body/nas/index.html">NAS管理</a>
</li>
</div>
<li class="layui-nav-item">
<a href="javascript:;">工具集</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;" target="_blank">密码管理器</a></dd>
<dd><a href="/html/body/tools/password.html">密码管理器</a></dd>
</dl>
</li>
<li class="layui-nav-item">
@@ -29,27 +29,63 @@
</dl>
</li>
<li class="layui-nav-item" id='icon'>
<a href="javascript:;" id="login"><img src="//t.cn/RCzsdCq" class="layui-nav-img">登录</a>
<a href="javascript:;" id="login"><img src="//t.cn/RCzsdCq" class="layui-nav-img"><span
id='login_text'>登录</span></a>
<dl class="layui-nav-child">
<dd><a href="javascript:;">退了</a></dd>
<dd><a href="javascript:;" id="logout">退了</a></dd>
</dl>
</li>
</ul>
</div>
</body>
<script>
let loginStatus = false;
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code == 0) {
$('#login_text').text('已登录')
loginStatus = true;
}
})
$('#login').click(function () {
if (loginStatus) {
return;
}
$.post('/login/sendCaptcha.do', function () {
layer.prompt({
title: '安全登录码'
}, function (value, index, elem) {
alert(value); //得到value
$.post('/login/login.do', { code: value }, function (data) {
let json = JSON.parse(data);
layer.msg(json.msg)
window.location.reload()
});
layer.close(index);
})
})
})
$('#logout').click(function () {
$.post('/login/logout.do', function (data) {
let json = JSON.parse(data);
layer.msg(json.msg)
window.location.href = "/"
})
})
$(document).ready(function () {
let mobile = navigator.userAgent.toLowerCase().match(/android/i) == "android" || navigator.userAgent.toLowerCase().match(/iphone os/i) == "iphone os";
if (mobile) {
$('.layui-body').css('left', '0')
$('.layui-body').css('top', '150px')
$('.layui-body').css('height', '200%')
$('#icon').css('float', 'none')
} else {
$('.layui-body').css('padding-right', '100px')
$('#icon').css('float', 'right')
}
})
</script>
<style>
</style>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,273 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
button {
border: 0;
outline: 0;
}
.container {
margin: 40px 0;
width: 400px;
padding: 10px 25px;
background: #0a0e31;
border-radius: 10px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.45), 0 4px 8px rgba(0, 0, 0, 0.35), 0 8px 12px rgba(0, 0, 0, 0.15);
font-family: "Montserrat";
}
.container h2.title {
font-size: 1.75rem;
margin: 10px -5px;
margin-bottom: 30px;
color: #fff;
}
.result {
position: relative;
width: 100%;
height: 65px;
overflow: hidden;
}
.result__info {
position: absolute;
bottom: 4px;
color: #fff;
font-size: 0.8rem;
transition: all 150ms ease-in-out;
transform: translateY(200%);
opacity: 0;
}
.result__info.right {
right: 8px;
}
.result__info.left {
left: 8px;
}
.result__viewbox {
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.08);
border-radius: 8px;
color: #fff;
text-align: center;
line-height: 65px;
}
.result #copy-btn {
position: absolute;
top: var(--y);
left: var(--x);
width: 38px;
height: 38px;
background: #fff;
border-radius: 50%;
opacity: 0;
transform: translate(-50%, -50%) scale(0);
transition: all 350ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
cursor: pointer;
z-index: 2;
}
.result #copy-btn:active {
box-shadow: 0 0 0 200px rgba(255, 255, 255, 0.08);
}
.result:hover #copy-btn {
opacity: 1;
transform: translate(-50%, -50%) scale(1.35);
}
.field-title {
position: absolute;
top: -10px;
left: 8px;
transform: translateY(-50%);
font-weight: 800;
color: rgba(255, 255, 255, 0.5);
text-transform: uppercase;
font-size: 0.65rem;
pointer-events: none;
user-select: none;
}
.options {
width: 100%;
height: auto;
margin: 50px 0;
}
.range__slider {
position: relative;
width: 100%;
height: calc(65px - 10px);
display: flex;
justify-content: center;
align-items: center;
background: rgba(255, 255, 255, 0.08);
border-radius: 8px;
margin: 30px 0;
}
.range__slider::before, .range__slider::after {
position: absolute;
color: #fff;
font-size: 0.9rem;
font-weight: bold;
}
.range__slider::before {
content: attr(data-min);
left: 10px;
}
.range__slider::after {
content: attr(data-max);
right: 10px;
}
.range__slider .length__title::after {
content: attr(data-length);
position: absolute;
right: -16px;
font-variant-numeric: tabular-nums;
color: #fff;
}
#slider {
-webkit-appearance: none;
width: calc(100% - (70px));
height: 2px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.314);
outline: none;
padding: 0;
margin: 0;
cursor: pointer;
}
#slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: white;
cursor: pointer;
transition: all 0.15s ease-in-out;
}
#slider::-webkit-slider-thumb:hover {
background: #d4d4d4;
transform: scale(1.2);
}
#slider::-moz-range-thumb {
width: 20px;
height: 20px;
border: 0;
border-radius: 50%;
background: white;
cursor: pointer;
transition: background 0.15s ease-in-out;
}
#slider::-moz-range-thumb:hover {
background: #d4d4d4;
}
.settings {
position: relative;
height: auto;
widows: 100%;
display: flex;
flex-direction: column;
}
.settings .setting {
position: relative;
width: 100%;
height: calc(65px - 10px);
background: rgba(255, 255, 255, 0.08);
border-radius: 8px;
display: flex;
align-items: center;
padding: 10px 25px;
color: #fff;
margin-bottom: 8px;
}
.settings .setting input {
opacity: 0;
position: absolute;
}
.settings .setting input + label {
user-select: none;
}
.settings .setting input + label::before, .settings .setting input + label::after {
content: "";
position: absolute;
transition: 150ms cubic-bezier(0.24, 0, 0.5, 1);
transform: translateY(-50%);
top: 50%;
right: 10px;
cursor: pointer;
}
.settings .setting input + label::before {
height: 30px;
width: 50px;
border-radius: 30px;
background: rgba(214, 214, 214, 0.434);
}
.settings .setting input + label::after {
height: 24px;
width: 24px;
border-radius: 60px;
right: 32px;
background: #fff;
}
.settings .setting input:checked + label:before {
background: #5d68e2;
transition: all 150ms cubic-bezier(0, 0, 0, 0.1);
}
.settings .setting input:checked + label:after {
right: 14px;
}
.settings .setting input:focus + label:before {
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75);
}
.btn.generate {
user-select: none;
position: relative;
width: 100%;
height: 50px;
margin: 10px 0;
border-radius: 8px;
color: #fff;
border: none;
background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
letter-spacing: 1px;
font-weight: bold;
text-transform: uppercase;
cursor: pointer;
transition: all 150ms ease;
}
.btn.generate:active {
transform: translateY(-3%);
box-shadow: 0 4px 8px rgba(255, 255, 255, 0.08);
}
.support {
position: fixed;
right: 10px;
bottom: 10px;
padding: 10px;
display: flex;
}
a {
margin: 0 20px;
color: #fff;
font-size: 2rem;
transition: all 400ms ease;
}
a:hover {
color: #222;
}

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>js随机密码生成器插件 - 源码之家</title>
<!--图标库-->
<link rel='stylesheet' href='css/font-awesome.min.css'>
<!--字体库-->
<!--<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Montserrat&amp;display=swap'>-->
<!--主要样式-->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<h2 class="title">密码生成器</h2>
<div class="result">
<div class="result__title field-title">生成的密码</div>
<div class="result__info right">点击复制</div>
<div class="result__info left">复制</div>
<div class="result__viewbox" id="result">点击生成</div>
<button id="copy-btn" style="--x: 0; --y: 0"><i class="far fa-copy"></i></button>
</div>
<div class="length range__slider" data-min="4" data-max="128">
<div class="length__title field-title" data-length='0'>长度:</div>
<input id="slider" type="range" min="4" max="128" value="16" />
</div>
<div class="settings">
<span class="settings__title field-title">settings</span>
<div class="setting">
<input type="checkbox" id="uppercase" checked />
<label for="uppercase">包含大写</label>
</div>
<div class="setting">
<input type="checkbox" id="lowercase" checked />
<label for="lowercase">包含小写</label>
</div>
<div class="setting">
<input type="checkbox" id="number" checked />
<label for="number">包括数字</label>
</div>
<div class="setting">
<input type="checkbox" id="symbol" />
<label for="symbol">包括符号</label>
</div>
</div>
<button class="btn generate" id="generate">生成密码</button>
</div>
<script src="js/script.js"></script>
<div style="text-align:center;">
</div>
</body>
</html>

View File

@@ -0,0 +1,152 @@
// This is a simple Password Generator App that will generate random password maybe you can you them to secure your account.
// I tried my best to make the code as simple as possible please dont mind the variable names.
// Also this idea came in my mind after checking Traversy Media's latest video.
// Clear the concole on every refresh
console.clear();
// Range Slider Properties.
// Fill : The trailing color that you see when you drag the slider.
// background : Default Range Slider Background
const sliderProps = {
fill: "#0B1EDF",
background: "rgba(255, 255, 255, 0.214)",
};
// Selecting the Range Slider container which will effect the LENGTH property of the password.
const slider = document.querySelector(".range__slider");
// Text which will show the value of the range slider.
const sliderValue = document.querySelector(".length__title");
// Using Event Listener to apply the fill and also change the value of the text.
slider.querySelector("input").addEventListener("input", event => {
sliderValue.setAttribute("data-length", event.target.value);
applyFill(event.target);
});
// Selecting the range input and passing it in the applyFill func.
applyFill(slider.querySelector("input"));
// This function is responsible to create the trailing color and setting the fill.
function applyFill(slider) {
const percentage = (100 * (slider.value - slider.min)) / (slider.max - slider.min);
const bg = `linear-gradient(90deg, ${sliderProps.fill} ${percentage}%, ${sliderProps.background} ${percentage +
0.1}%)`;
slider.style.background = bg;
sliderValue.setAttribute("data-length", slider.value);
}
// Object of all the function names that we will use to create random letters of password
const randomFunc = {
lower: getRandomLower,
upper: getRandomUpper,
number: getRandomNumber,
symbol: getRandomSymbol,
};
// Generator Functions
// All the functions that are responsible to return a random value taht we will use to create password.
function getRandomLower() {
return String.fromCharCode(Math.floor(Math.random() * 26) + 97);
}
function getRandomUpper() {
return String.fromCharCode(Math.floor(Math.random() * 26) + 65);
}
function getRandomNumber() {
return String.fromCharCode(Math.floor(Math.random() * 10) + 48);
}
function getRandomSymbol() {
const symbols = '~!@#$%^&*()_+{}":?><;.,';
return symbols[Math.floor(Math.random() * symbols.length)];
}
// Selecting all the DOM Elements that are necessary -->
// The Viewbox where the result will be shown
const resultEl = document.getElementById("result");
// The input slider, will use to change the length of the password
const lengthEl = document.getElementById("slider");
// Checkboxes representing the options that is responsible to create differnt type of password based on user
const uppercaseEl = document.getElementById("uppercase");
const lowercaseEl = document.getElementById("lowercase");
const numberEl = document.getElementById("number");
const symbolEl = document.getElementById("symbol");
// Button to generate the password
const generateBtn = document.getElementById("generate");
// Button to copy the text
const copyBtn = document.getElementById("copy-btn");
// Result viewbox container
const resultContainer = document.querySelector(".result");
// Text info showed after generate button is clicked
const copyInfo = document.querySelector(".result__info.right");
// Text appear after copy button is clicked
const copiedInfo = document.querySelector(".result__info.left");
// Update Css Props of the COPY button
// Getting the bounds of the result viewbox container
let resultContainerBound = {
left: resultContainer.getBoundingClientRect().left,
top: resultContainer.getBoundingClientRect().top,
};
// This will update the position of the copy button based on mouse Position
resultContainer.addEventListener("mousemove", e => {
copyBtn.style.setProperty("--x", `${e.x - resultContainerBound.left}px`);
copyBtn.style.setProperty("--y", `${e.y - resultContainerBound.top}px`);
});
window.addEventListener("resize", e => {
resultContainerBound = {
left: resultContainer.getBoundingClientRect().left,
top: resultContainer.getBoundingClientRect().top,
};
});
// Copy Password in clipboard
copyBtn.addEventListener("click", () => {
const textarea = document.createElement("textarea");
const password = resultEl.innerText;
if (!password || password == "CLICK GENERATE") {
return;
}
textarea.value = password;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
copyInfo.style.transform = "translateY(200%)";
copyInfo.style.opacity = "0";
copiedInfo.style.transform = "translateY(0%)";
copiedInfo.style.opacity = "0.75";
});
// When Generate is clicked Password id generated.
generateBtn.addEventListener("click", () => {
const length = +lengthEl.value;
const hasLower = lowercaseEl.checked;
const hasUpper = uppercaseEl.checked;
const hasNumber = numberEl.checked;
const hasSymbol = symbolEl.checked;
resultEl.innerText = generatePassword(length, hasLower, hasUpper, hasNumber, hasSymbol);
copyInfo.style.transform = "translateY(0%)";
copyInfo.style.opacity = "0.75";
copiedInfo.style.transform = "translateY(200%)";
copiedInfo.style.opacity = "0";
});
// Function responsible to generate password and then returning it.
function generatePassword(length, lower, upper, number, symbol) {
let generatedPassword = "";
const typesCount = lower + upper + number + symbol;
const typesArr = [{ lower }, { upper }, { number }, { symbol }].filter(item => Object.values(item)[0]);
if (typesCount === 0) {
return "";
}
for (let i = 0; i < length; i++) {
typesArr.forEach(type => {
const funcName = Object.keys(type)[0];
generatedPassword += randomFunc[funcName]();
});
}
return generatedPassword.slice(0, length);
}