Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

兼容ie8 #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/config/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ exports.model = {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: 'root',
dateStrings: true
password: 'admin',
dateStrings: true,
pageSize: 10, // 设置默认每页为 10 条
connectionLimit: 5 // 连接池的连接个数,默认为 1
}
};

Expand Down
40 changes: 22 additions & 18 deletions src/controller/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@ const Base = require('./base.js');

module.exports = class extends Base {
indexAction() {
return this.display();
return this.display();
}
/**
* 登录
*/
async loginAction(){
if (this.isPost){//判断是否发送信息给后台了,post数据过来.注意:isPost中的P是大写,js是对大小写敏感的。
let username = this.post('username');//获取用户名给username变量
let password = this.post('password');
let data = await this.model('thinkjsplus_user').where({username:username,password:password}).find();//到数据库中去查找看是否有数据(用户名密码同时相符)
if (think.isEmpty(data)){//这里我直接用isEmpty居然不能用。查了下资料需要用think.isEmpty()
return this.fail(403,'账号密码错误!请重新填写');//登录不成功,返回错误信息。
}else{
this.session('userinfo',data);
return this.redirect('/index/index');//登录成功将用户信息写入session,返回到user首页。
}
}
return this.display();
async loginAction() {
if (this.isPost) { // 判断是否发送信息给后台了,post数据过来.注意:isPost中的P是大写,js是对大小写敏感的。
const username = this.post('username');// 获取用户名给username变量
const password = this.post('password');
const data = await this.model('thinkjsplus_user').where({username: username, password: password}).find();// 到数据库中去查找看是否有数据(用户名密码同时相符)
if (think.isEmpty(data)) { // 这里我直接用isEmpty居然不能用。查了下资料需要用think.isEmpty()
return this.fail(403, '账号密码错误!请重新填写');// 登录不成功,返回错误信息。
} else {
this.session('userinfo', data);
// return this.redirect('/index/index');// 登录成功将用户信息写入session,返回到user首页。
return this.json({
errno: '000',
errmsg: ''
});
}
}
return this.display();
}
/**
* 注销
*/
async logoutAction(){
await this.session(null);
return this.redirect('/index/index');//登录成功将用户信息写入session,返回到user首页。
}
async logoutAction() {
await this.session(null);
return this.redirect('/index/index');// 登录成功将用户信息写入session,返回到user首页。
}
};
20 changes: 11 additions & 9 deletions src/controller/base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module.exports = class extends think.Controller {
async __before() {
if(this.ctx.controller === 'admin' && this.ctx.action === 'index'||this.ctx.action === 'login' ){ //如果是admin_index那么久不验证了,直接返回给予登录。
return;
}
let userinfo =await this.session('userinfo')
if (!think.isEmpty(userinfo)){
this.assign('userinfo',userinfo);
}else{
return this.redirect('/admin/index');
}
console.log('this.ctx.controller,this.ctx.action:', this.ctx.controller, this.ctx.action);
if ((this.ctx.controller === 'admin' && this.ctx.action === 'index') || this.ctx.action === 'login') { // 如果是admin_index那么久不验证了,直接返回给予登录。
return;
}
const userinfo = await this.session('userinfo');
console.log('this.session(\'userinfo\'):', userinfo);
if (!think.isEmpty(userinfo)) {
this.assign('userinfo', userinfo);
} else {
return this.redirect('/admin/index');
}
}
};
33 changes: 17 additions & 16 deletions src/controller/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,43 @@ module.exports = class extends Base {
* 保存分类
*/
async saveAction() {
let data = this.post();
const data = this.post();
if (think.isEmpty(data.id)) {
//保存
let res = await this.model("thinkjsplus_category").add(data);
// 保存
const res = await this.model('thinkjsplus_category').add(data);
if (res) {
this.json({"succ":true});
this.json({'succ': true});
} else {
this.json({"succ":false});
this.json({'succ': false});
}
} else {
//更新
let res = await this.model("thinkjsplus_category").update(data);
// 更新
const res = await this.model('thinkjsplus_category').update(data);
if (res) {
this.json({"succ":true});
this.json({'succ': true});
} else {
this.json({"succ":false});
this.json({'succ': false});
}
}
}
/**
* 删除分类
*/
async delAction() {
let categoryModel = this.model("thinkjsplus_category");
let posts = this.post("id");
let delNums = categoryModel.where({id: ['IN', posts]}).delete();
if(delNums){
this.json({"succ":true});
}else{
this.json({"succ":false});
const categoryModel = this.model('thinkjsplus_category');
const posts = this.post('id');
const delNums = categoryModel.where({id: ['IN', posts]}).delete();
if (delNums) {
this.json({'succ': true});
} else {
this.json({'succ': false});
}
}
/**
* 查看分类
*/
async listAction() {
// 请求url: /category/list
const user = this.model('thinkjsplus_category'); // controller 里实例化模型
const data = await user.select();
return this.json(data);
Expand Down
1 change: 1 addition & 0 deletions src/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = class extends Base {
// }else{
// return this.redirect('/admin/index');
// }
console.log('user.select:', data);
this.assign('title',"测试网页之hello world!");
return this.display();
}
Expand Down
33 changes: 16 additions & 17 deletions src/controller/thing.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ module.exports = class extends Base {
* 保存分类
*/
async saveAction() {
let data = this.post();
const data = this.post();
console.log(data);
if (think.isEmpty(data.id)) {
//保存
let res = await this.model("thinkjsplus_thing").add(data);
// 保存
const res = await this.model('thinkjsplus_thing').add(data);
if (res) {
this.json({"succ":true});
this.json({'succ': true});
} else {
this.json({"succ":false});
this.json({'succ': false});
}
} else {
//更新
let res = await this.model("thinkjsplus_thing").update(data);
// 更新
const res = await this.model('thinkjsplus_thing').update(data);
if (res) {
this.json({"succ":true});
this.json({'succ': true});
} else {
this.json({"succ":false});
this.json({'succ': false});
}
}
}
Expand All @@ -46,14 +46,13 @@ module.exports = class extends Base {
* 删除事情
*/
async delAction() {
let thingModel = this.model("thinkjsplus_thing");
let posts = this.post("id");
let delNums = thingModel.where({id: ['IN', posts]}).delete();
if(delNums){
this.json({"succ":true});
}else{
this.json({"succ":false});
const thingModel = this.model('thinkjsplus_thing');
const posts = this.post('id');
const delNums = thingModel.where({id: ['IN', posts]}).delete();
if (delNums) {
this.json({'succ': true});
} else {
this.json({'succ': false});
}
}

};
42 changes: 40 additions & 2 deletions view/admin_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>thinjsplus登录</title>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<title>thinjsplus登录(admin_index)</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/htmleaf-demo.css">
Expand Down Expand Up @@ -135,14 +136,19 @@
}
}
</style>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="htmleaf-container">
<div class="demo form-bg" style="padding: 150px 0;">
<div class="container">
<div class="row">
<div class="col-md-offset-3 col-md-6">
<form class="form-horizontal" action="/admin/login" method="POST">
<!-- action="/admin/login" method="POST" -->
<form id="form1" class="form-horizontal">
<span class="heading">登录</span>
<div class="form-group">
<input type="text" class="form-control" name="username" id="username" placeholder="用户名">
Expand All @@ -167,5 +173,37 @@
</div>
</div>
</div>
<!-- stz+ s -->
{% include "./footer.html" %}
<script>
$(function(){
$('#form1').bind('submit', function(e){
// var form1 = $(this);
e.preventDefault();
e.stopPropagation();
$.ajax({
type:'post',
url:'/admin/login',
data:{
username:$('#username').val(),
password:$('#password').val()
},
dataType:'json',
success:function(re){
console.log(re);
if(re.errno!='000' && re.errmsg){
alert(re.errmsg);
return;
}
location.href = '/index/index';
},
error:function(){
console.log(arguments);
}
});
});
})
</script>
<!-- stz+ e -->
</body>
</html>
7 changes: 4 additions & 3 deletions view/category_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<tbody>
</tbody>
</table>
{% include "./footer.html" %}

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand All @@ -46,13 +46,14 @@ <h4 class="modal-title" id="myModalLabel">编辑</h4>
</div>
</div>
</div>
</div>
</div>
{% include "./footer.html" %}
</body>
<script>
$(function () {
$.ajax({
type: 'get',
url: 'http://127.0.0.1:8360/category/list',
url: '/category/list',
success: function (data) {
//DataTable
var table = $('#example2').DataTable({
Expand Down
17 changes: 13 additions & 4 deletions view/footer.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<!-- jQuery 3 -->
<script src="/static/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script>
//ie8以上浏览器 http://caibaojian.com/detect-ie-version.html
if(!document.all || !!document.addEventListener){
document.write('<script src="\/static\/bower_components\/jquery\/dist\/jquery.min.js"><\/script>');
}
</script>
<!--IE8只能支持jQuery1.9.0 https://zhidao.baidu.com/question/620092104251052092.html -->
<!--[if lte IE 8]>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<![endif]-->
<!-- Bootstrap 3.3.7 .min -->
<script src="/static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- AdminLTE App -->
<!-- AdminLTE App .min -->
<script src="/static/dist/js/adminlte.min.js"></script>
<!-- DataTables -->
<script src="/static/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="/static/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="/static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="/static/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="/static/bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="/static/dist/js/config.js"></script>
4 changes: 4 additions & 0 deletions view/header.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/bower_components/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/static/bower_components/Ionicons/css/ionicons.min.css">
<link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css">
<link rel="stylesheet" href="/static/dist/css/skins/skin-blue.min.css">
<link rel="stylesheet" href="/static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<link rel="stylesheet" href="/static/dist/css/style.css">
<!--IE8只能支持jQuery1.9 https://zhidao.baidu.com/question/620092104251052092.html -->
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
10 changes: 5 additions & 5 deletions view/index_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<html>
<head>
<meta charset="UTF-8">
<title>thinkjsPlus</title>
<title>{{title}}</title>
{% include "./header.html" %}
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<!-- Main Header -->
<header class="main-header">
<!-- Logo -->
<a href="" class="logo">
<a href="javascript:void(0)" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini">Plus</span>
<!-- logo for regular state and mobile devices -->
Expand All @@ -19,7 +19,7 @@
<!-- Header Navbar -->
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<a href="javascript:void(0)" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
<!-- Navbar Right Menu -->
Expand All @@ -46,7 +46,7 @@
<!-- Sidebar Menu -->
<ul class="sidebar-menu" data-widget="tree">
<li class="treeview">
<a href="#"><i class="fa fa-book"></i> <span>记事分类</span>
<a href="javascript:void(0)"><i class="fa fa-book"></i> <span>记事分类</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
Expand All @@ -57,7 +57,7 @@
</ul>
</li>
<li class="treeview">
<a href="#"><i class="fa fa-list"></i> <span>记事列表</span>
<a href="javascript:void(0)"><i class="fa fa-list"></i> <span>记事列表</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
Expand Down
Loading