Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OPENTECH
/
yoho-node-ci
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
2
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
shijian
8 years ago
Commit
96f448ed9822b6d40fed2cb5969ba963f8da4ed4
1 parent
8d4c6c0b
save
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
23 deletions
apps/web/actions/keywords.js
apps/web/views/action/keywords.hbs
apps/web/actions/keywords.js
View file @
96f448e
...
...
@@ -17,10 +17,6 @@ client.on("error", function (err) {
console
.
log
(
"Error "
+
err
);
});
const
{
OperationLogger
}
=
require
(
'../../models'
);
const
r
=
new
Router
();
const
multiAsync
=
()
=>
{
...
...
@@ -34,8 +30,11 @@ const multiAsync=()=>{
}
//查看
const
getDataList
=
async
(
key
)
=>
{
multi
.
lrange
(
"keywords_mana_list"
,
0
,
-
1
);
const
getDataList
=
async
(
key
,
page
)
=>
{
let
start
=
(
page
-
1
)
*
10
;
let
end
=
(
page
)
*
10
-
1
;
multi
.
lrange
(
key
,
start
,
end
);
multi
.
LLEN
(
key
);
return
multiAsync
();
}
...
...
@@ -58,12 +57,13 @@ const delDataValues = async(arr)=>{
const
addDataValues
=
async
(
value
)
=>
{
let
key
=
`
keywords_mana
:
$
{
value
}
`
;
multi
.
set
(
key
,
value
);
multi
.
lrem
(
'keywords_mana_list'
,
1
,
key
);
multi
.
lpush
(
'keywords_mana_list'
,
key
);
return
multiAsync
();
}
//编辑
const
editDataValues
=
async
(
value
,
oldValue
)
=>
{
console
.
log
(
value
,
oldValue
);
const
editDataValues
=
async
(
value
,
oldValue
)
=>
{
try
{
await
delDataValues
([
oldValue
]);
await
addDataValues
(
value
);
...
...
@@ -80,12 +80,14 @@ r.get('/', async(ctx) => {
r
.
get
(
'/getKeywords'
,
async
(
ctx
)
=>
{
let
q
=
ctx
.
request
.
query
;
let
r
=
await
getDataList
(
"keywords_mana_list"
);
console
.
log
(
r
);
let
result
=
await
getDataValues
(
r
);
let
r
=
await
getDataList
(
"keywords_mana_list"
,
q
.
currentPage
,
q
.
pageCount
);
let
result
=
[];
if
(
r
[
0
].
length
)
result
=
await
getDataValues
(
r
[
0
]);
ctx
.
body
=
{
code
:
200
,
message
:
'success'
,
data
:
result
data
:
result
,
total
:
r
[
1
]
};
});
...
...
apps/web/views/action/keywords.hbs
View file @
96f448e
...
...
@@ -17,9 +17,9 @@
<div
class=
"contentpanel project-index-page"
style=
"padding-bottom:0;"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-body"
>
<label
style=
"margin-right:20px;"
><input
type=
"checkbox"
style=
"margin-right:5px;"
>
全选
</label>
<label
style=
"margin-right:20px;"
><input
id=
"allSelected"
type=
"checkbox"
style=
"margin-right:5px;"
>
全选
</label>
<a
data-toggle=
"modal"
href=
"#pop"
class=
"btn btn-default"
style=
"margin-right:10px;"
>
增加
</a>
<
button
class=
"btn btn-default"
type=
"submit"
>
删除
</button
>
<
a
class=
"btn btn-default deleteAll"
>
删除
</a
>
</div>
</div>
</div>
...
...
@@ -41,17 +41,15 @@
<div
class=
"panel panel-default"
>
<div
class=
"panel-body"
>
<table
id=
"table-oper-log"
class=
"table table-striped table-bordered building-table"
>
<thead>
<tr>
<th>
ID
</th>
<th>
关键词
</th>
<th>
操作
</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<ul
class=
"pager"
>
<li><a
class=
"privious pages"
>
上一页
</a></li>
<li><a
class=
"next pages"
>
下一页
</a></li>
</ul>
<style>
.nostyle
{
background
:
transparent
;
...
...
@@ -74,21 +72,62 @@
bottom
:
0
;
margin
:
auto
;
}
.pager
{
float
:
right
;
margin-right
:
20px
;
margin-top
:
0
;
}
.pages
{
cursor
:
pointer
;
}
</style>
<script>
var
currentPage
=
1
,
pageCount
=
10
,
pageTotal
;
var
tabHead
=
'<thead><tr><th>ID</th><th>关键词</th><th>操作</th></tr></thead>'
;
//展示列表
$
(
document
).
on
(
'ready pjax:success'
,
function
()
{
$
.
get
(
'/keywords/getKeywords'
,
function
(
data
){
$
.
get
(
'/keywords/getKeywords?'
,
{
currentPage
:
currentPage
,
pageCount
:
pageCount
},
function
(
data
){
var
html
=
''
;
let
datas
=
data
.
data
;
if
(
datas
){
datas
.
forEach
(
function
(
item
,
index
){
html
+=
tableHtml
(
item
,
index
);
});
$
(
'#table-oper-log'
).
html
(
tabHead
+
html
);
pageTotal
=
Math
.
ceil
(
data
.
total
/
pageCount
);
}
});
});
$
(
'.privious'
).
on
(
'click'
,
function
()
{
if
(
currentPage
==
1
)
return
;
$
.
get
(
'/keywords/getKeywords?'
,{
currentPage
:
--
currentPage
,
pageCount
:
pageCount
},
function
(
data
){
var
html
=
''
;
let
datas
=
data
.
data
;
if
(
datas
){
datas
.
forEach
(
function
(
item
,
index
){
html
+=
tableHtml
(
item
,
index
);
});
$
(
'#table-oper-log'
).
html
(
tabHead
+
html
);
}
});
});
$
(
'.next'
).
on
(
'click'
,
function
()
{
if
(
currentPage
>=
pageTotal
)
return
;
$
.
get
(
'/keywords/getKeywords?'
,{
currentPage
:
++
currentPage
,
pageCount
:
pageCount
},
function
(
data
){
var
html
=
''
;
let
datas
=
data
.
data
;
if
(
datas
){
datas
.
forEach
(
function
(
item
,
index
){
html
+=
'<tr><td><label><input type="checkbox">'
+
index
+
'</label></td><td><input value="'
+
item
+
'" disabled></td><td><button class="btn btn-default nostyle edit">编辑</button><button class="btn btn-default nostyle delete">删除</button></td></tr>'
;
html
+=
tableHtml
(
item
,
index
)
;
});
$
(
'#table-oper-log'
).
html
(
$
(
'#table-oper-log'
).
html
()
+
html
);
$
(
'#table-oper-log'
).
html
(
tabHead
+
html
);
}
});
});
//删除
$
(
document
).
on
(
'click'
,
'.delete'
,
function
(){
var
val
=
$
(
$
(
this
).
parents
(
'tr'
).
find
(
'input'
)[
1
]).
val
();
var
parent
=
$
(
this
).
parents
(
'tr'
);
...
...
@@ -108,7 +147,14 @@
var
val
=
input
.
val
();
$
.
get
(
'/keywords/editKeywords'
,
{
keywords
:
JSON
.
stringify
([
val
,
oldValue
])},
function
(
data
){
if
(
data
.
code
===
200
){
input
.
attr
(
'disabled'
,
true
);
var
isSame
=
false
;
$
(
'table .values'
).
each
(
function
(){
if
(
$
(
this
)
!=
input
){
if
(
$
(
this
).
val
()
==
input
.
val
())
isSame
=
true
;
}
});
if
(
isSame
)
location
.
reload
();
else
input
.
attr
(
'disabled'
,
true
);
}
});
});
...
...
@@ -122,4 +168,27 @@
}
});
});
//全选
$
(
'#allSelected'
).
on
(
'click'
,
function
(){
var
check
=
false
;
if
(
$
(
this
).
attr
(
'checked'
)){
check
=
true
;
}
$
(
"table :checkbox"
).
attr
(
"checked"
,
check
);
});
$
(
'.deleteAll'
).
on
(
'click'
,
function
(){
let
arr
=
[];
$
(
"table :checkbox:checked"
).
each
(
function
(
item
){
arr
.
push
(
$
(
$
(
this
).
parents
(
'tr'
).
find
(
'input'
)[
1
]).
val
());
});
if
(
!
arr
.
length
)
return
;
$
.
get
(
'/keywords/delKeywords'
,
{
keywords
:
JSON
.
stringify
(
arr
)},
function
(
data
){
if
(
data
.
code
===
200
){
location
.
reload
();
}
});
});
function
tableHtml
(
item
,
index
){
return
'<tr><td><label><input type="checkbox">'
+
index
+
'</label></td><td><input class="values" value="'
+
item
+
'" disabled></td><td><button class="btn btn-default nostyle edit">编辑</button><button class="btn btn-default nostyle delete">删除</button></td></tr>'
;
}
</script>
\ No newline at end of file
...
...
Please
register
or
login
to post a comment