home.html 14 KB

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