home.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <html lang="zh">
  2. <head>
  3. <title>管理员主页</title>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  6. <script src="/jquery.min.js"></script>
  7. <script src="/vue.js"></script>
  8. <script src="/elementui.js"></script>
  9. <script src="/js.cookie.min.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/elementui.css">
  11. <style>
  12. * {
  13. margin: 0;
  14. padding: 0;
  15. }
  16. .font {
  17. font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  18. }
  19. .right {
  20. float: left;
  21. padding: 20px;
  22. width: calc(100% - 240px);
  23. overflow: auto;
  24. height: calc(100% - 40px);
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id="app">
  30. <div style="float:left; width:200px; height: 100%;">
  31. <!-- 菜单项 -->
  32. <el-menu style="height:100%;" :default-active="activeIndex" @select="handleSelect">
  33. <el-menu-item index="1">
  34. <i class="el-icon-coin"></i>
  35. <span slot="title">日志</span>
  36. </el-menu-item>
  37. <el-menu-item index="2">
  38. <i class="el-icon-zoom-in"></i>
  39. <span slot="title">详情</span>
  40. </el-menu-item>
  41. <li style="padding: 0 20px;box-sizing: border-box;text-align: center;">
  42. <el-popconfirm title="确定要退出登录吗?" @confirm="logout">
  43. <el-button slot="reference" style="margin-top: 20px;">退出登录</el-button>
  44. </el-popconfirm>
  45. </li>
  46. </el-menu>
  47. </div>
  48. <div class="right" v-show="activeIndex==='1'">
  49. <el-table :data="logData" stripe style="width: 100%;">
  50. <el-table-column prop="time" label="时间" width="180">
  51. </el-table-column>
  52. <el-table-column prop="name" label="姓名" width="310">
  53. </el-table-column>
  54. <el-table-column prop="type" label="类型" width="180">
  55. </el-table-column>
  56. <el-table-column prop="msg" label="消息">
  57. </el-table-column>
  58. </el-table>
  59. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="data.page" :page-size="data.len" :page-sizes="[10, 20, 30, 50, 100]" layout="sizes, total, prev, pager, next" :total="data.count">
  60. </el-pagination>
  61. </div>
  62. <div class="right" v-show="activeIndex==='2'">
  63. <el-table :data="detailsData" stripe style="width: 100%;">
  64. <el-table-column prop="name" label="姓名" width="310">
  65. </el-table-column>
  66. <el-table-column prop="time" label="首次完成时间" width="180">
  67. </el-table-column>
  68. <el-table-column prop="fail" label="失败提交次数" width="180">
  69. </el-table-column>
  70. <el-table-column prop="fail" label="查看实验账号密码">
  71. <template slot-scope="scope">
  72. <el-button @click="handleClick(scope.row.id, scope.row.name)">查看</el-button>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. </div>
  77. <div>
  78. <el-dialog :title="showKeyUser" :visible="userKey!==null" width="50%" :show-close="false">
  79. <el-table :data="msgData" stripe style="height: 50%;" height="50%">
  80. <el-table-column prop="time" label="时间">
  81. </el-table-column>
  82. <el-table-column prop="msg" label="账号密码">
  83. </el-table-column>
  84. </el-table>
  85. <span slot="footer" class="dialog-footer">
  86. <el-button type="primary" @click="handleClose">确定</el-button>
  87. </span>
  88. </el-dialog>
  89. </div>
  90. </div>
  91. <script>
  92. var app;
  93. var vue = new Vue({
  94. el: '#app',
  95. data: {
  96. apiUrl: '/api',
  97. isLoading: false,
  98. activeIndex: "",
  99. data: {
  100. count: 0,
  101. page: 1,
  102. len: 10,
  103. data: [],
  104. interval: -1
  105. },
  106. details: {
  107. data: [],
  108. interval: -1
  109. },
  110. userKey: null,
  111. showKeyUser: ""
  112. },
  113. computed: {
  114. msgData: function() {
  115. if (!this.userKey) {
  116. return []
  117. }
  118. for (var i = 0, j = this.userKey.length; i < j; i++) {
  119. if (this.userKey[i]["time"] === 0) {
  120. this.userKey[i]["time"] = "";
  121. }
  122. else {
  123. this.userKey[i]["time"] = this.formatDate(this.userKey[i]["time"]);
  124. }
  125. }
  126. return this.userKey;
  127. },
  128. detailsData: function() {
  129. for (var i = 0, j = this.details.data.length; i < j; i++) {
  130. if (this.details.data[i]["time"] === 0) {
  131. this.details.data[i]["time"] = "";
  132. }
  133. else {
  134. this.details.data[i]["time"] = this.formatDate(this.details.data[i]["time"]);
  135. }
  136. }
  137. return this.details.data;
  138. },
  139. logData: function() {
  140. for (var i = 0, j = this.data.data.length; i < j; i++) {
  141. if (this.data.data[i]["time"] === 0) {
  142. this.data.data[i]["time"] = "";
  143. }
  144. else {
  145. this.data.data[i]["time"] = this.formatDate(this.data.data[i]["time"]);
  146. }
  147. switch (this.data.data[i]["type"]) {
  148. case 0:
  149. this.data.data[i]["type"] = "提交URL";
  150. break;
  151. case 1:
  152. this.data.data[i]["type"] = "URL结果匹配成功!!";
  153. break;
  154. case 2:
  155. this.data.data[i]["type"] = "URL结果匹配失败";
  156. break;
  157. case 3:
  158. this.data.data[i]["type"] = "提交实验账号";
  159. break;
  160. default:
  161. this.data.data[i]["type"] = "";
  162. break;
  163. }
  164. }
  165. return this.data.data;
  166. },
  167. },
  168. methods: {
  169. req(url, method, data) {
  170. data = data ? JSON.stringify(data) : "";
  171. return new Promise(function(resolve, reject) {
  172. $.ajax({
  173. type: method,
  174. url: url,
  175. data: data ? data : "",
  176. contentType: data ? "application/json" : "",
  177. success: function(data) {
  178. resolve(data);
  179. },
  180. error: function(err) {
  181. reject(err);
  182. }
  183. });
  184. });
  185. },
  186. getDetails() {
  187. this.req(this.apiUrl + "/log/get/details", "GET", null).then((data) => {
  188. this.details.data = data;
  189. }).catch((err) => {
  190. this.logoutAlert("服务器错误8");
  191. });
  192. },
  193. logoutAlert(msg) {
  194. this.$alert(msg, '错误', {
  195. showClose: false,
  196. confirmButtonText: '重新登录',
  197. callback: action => {
  198. this.logout();
  199. }
  200. });
  201. },
  202. logout() {
  203. Cookies.set("admin_token", "");
  204. location.href = "/admin";
  205. },
  206. getData() {
  207. this.req(this.apiUrl + "/admin/get", "POST", { page: this.data.page, length: this.data.len }).then((data) => {
  208. if (data && data["success"]) {
  209. this.data.data = data["msg"]["data"];
  210. this.data.count = data["msg"]["count"];
  211. }
  212. else {
  213. logoutAlert("无法获取数据");
  214. }
  215. }).catch((err) => {
  216. logoutAlert("未知错误");
  217. });
  218. },
  219. formatDate: function(timestamp) {
  220. var d = new Date(timestamp * 1000);
  221. return d.getFullYear() + "-" + ((d.getMonth() + 1 >= 10) ? (d.getMonth() + 1) : "0" + (d.getMonth() + 1)) + "-" + ((d.getDate() >= 10) ? d.getDate() + "" : "0" + d.getDate()) + " " + ((d.getHours() >= 10) ? d.getHours() + "" : "0" + d.getHours()) + ":" + ((d.getMinutes() >= 10) ? d.getMinutes() + "" : "0" + d.getMinutes()) + ":" + ((d.getSeconds() >= 10) ? d.getSeconds() + "" : "0" + d.getSeconds());
  222. },
  223. handleSizeChange: function(size) {
  224. this.data.len = size;
  225. this.getData();
  226. },
  227. handleCurrentChange: function(page) {
  228. this.data.page = page;
  229. this.getData();
  230. },
  231. handleSelect: function(index) {
  232. if (index === this.activeIndex) {
  233. return;
  234. }
  235. if (index === "1") {
  236. this.getData();
  237. var self = this;
  238. this.data.interval = setInterval(function() { self.getData(); }, 3000);
  239. }
  240. else {
  241. clearInterval(this.data.interval);
  242. }
  243. if (index === "2") {
  244. this.getDetails();
  245. var self = this;
  246. this.details.interval = setInterval(function() { self.getDetails(); }, 3000);
  247. }
  248. else {
  249. clearInterval(this.details.interval);
  250. }
  251. Cookies.set("admin_page", index);
  252. this.activeIndex = index;
  253. },
  254. handleClick: function(id, name) {
  255. this.showKeyUser = name;
  256. this.req(this.apiUrl + "/admin/key/get", "POST", { id: id }).then((data) => {
  257. if (data["success"]) {
  258. this.userKey = data["msg"];
  259. }
  260. else {
  261. this.$message.closeAll();
  262. this.$message({
  263. type: 'error',
  264. showClose: true,
  265. message: data["msg"]
  266. });
  267. }
  268. }).catch((err) => {
  269. this.$message.closeAll();
  270. this.$message({
  271. type: 'error',
  272. showClose: true,
  273. message: "服务器错误"
  274. });
  275. });
  276. },
  277. handleClose: function() {
  278. this.userKey = null;
  279. }
  280. },
  281. mounted: function() {
  282. app = this;
  283. var token = Cookies.get("admin_token");
  284. if (token) {
  285. this.req(this.apiUrl + "/admin/login/cookie", "GET", null).then((data) => {
  286. if (!data || !data["success"]) {
  287. Cookies.set("admin_token", "");
  288. logoutAlert(data["msg"]);
  289. }
  290. }).catch(() => {
  291. logoutAlert(data["msg"]);
  292. Cookies.set("admin_token", "");
  293. });
  294. }
  295. var page = Cookies.get("admin_page");
  296. if (page) {
  297. this.handleSelect(page);
  298. }
  299. else {
  300. this.handleSelect("1");
  301. }
  302. // this.getData();
  303. // this.getDetails();
  304. }
  305. });
  306. </script>
  307. </body>
  308. </html>