api-log-list.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>api访问记录-列表</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <!-- 所有的 css & js 资源 -->
  8. <link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
  9. <link rel="stylesheet" href="../../static/sa.css">
  10. <script src="../../static/kj/vue.min.js"></script>
  11. <script src="../../static/kj/element-ui/index.js"></script>
  12. <script src="../../static/kj/httpVueLoader.js"></script>
  13. <script src="../../static/kj/jquery.min.js"></script>
  14. <script src="../../static/kj/layer/layer.js"></script>
  15. <script src="../../static/sa.js"></script>
  16. <style>
  17. .req-type-box{color: #FFF;}
  18. .req-type-box b{padding: 3px 7px; border-radius: 3px; font-size: 12px;}
  19. /* .req-api span{background-color: ; color: #409EFF; border: 1px #409EFF solid; border-radius: 2px; padding: 3px 5px;} */
  20. .req-api span{color: #44f; font-weight: 700; margin-left: 3px;}
  21. .req-p{display: inline-block; line-height: 1.4; padding: 2px 4px; border-radius: 4px; cursor: pointer;background-color: #fff2f4; color: #c7254e;}
  22. .req-ip{background-color: ; color: #409EFF; border: 1px #409EFF solid; border-radius: 2px; padding: 3px 5px;}
  23. .req-string{line-height: 1.4; padding: 2px 4px; border-radius: 4px;cursor: pointer; background-color: #ECF5FF;}
  24. </style>
  25. </head>
  26. <body>
  27. <div class="vue-box" style="display: none;" :style="'display: block;'">
  28. <div class="c-panel">
  29. <!-- 参数栏 -->
  30. <div class="c-title">检索参数</div>
  31. <el-form :inline="true" @submit.native.prevent>
  32. <el-form-item label="记录id:">
  33. <el-input v-model="p.id" placeholder="精确定位"></el-input>
  34. </el-form-item>
  35. <el-form-item label="请求ip:">
  36. <el-input v-model="p.reqIp" placeholder="IP筛选"></el-input>
  37. </el-form-item>
  38. <el-form-item label="请求api:">
  39. <el-input v-model="p.reqApi" placeholder="API接口筛选"></el-input>
  40. </el-form-item>
  41. <el-form-item style="min-width: 0px;">
  42. <el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
  43. </el-form-item>
  44. <br>
  45. <el-form-item label="请求token:">
  46. <el-input v-model="p.reqToken" placeholder="定向跟踪token"></el-input>
  47. </el-form-item>
  48. <el-form-item label="userId:">
  49. <el-input v-model="p.userId" placeholder="定向跟踪用户"></el-input>
  50. </el-form-item>
  51. <el-form-item label="adminId:">
  52. <el-input v-model="p.adminId" placeholder="定向跟踪用户"></el-input>
  53. </el-form-item>
  54. <br>
  55. <el-form-item label="res状态码:">
  56. <el-input v-model="p.resCode" placeholder="状态码筛选"></el-input>
  57. </el-form-item>
  58. <el-form-item label="请求时间:">
  59. <el-date-picker v-model="p.sTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="开始日期"></el-date-picker>
  60. -
  61. <el-date-picker v-model="p.eTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="结束日期"></el-date-picker>
  62. </el-form-item>
  63. <br />
  64. <el-form-item label="综合排序:" class="s-radio-text">
  65. <el-radio-group v-model="p.sortType">
  66. <el-radio :label="0">默认</el-radio>
  67. <el-radio :label="1">请求时间</el-radio>
  68. <el-radio :label="2">请求耗时</el-radio>
  69. </el-radio-group>
  70. </el-form-item>
  71. </el-form>
  72. <!-- ------------- 快捷按钮 ------------- -->
  73. <div class="fast-btn" style="margin-top: -10px;">
  74. <el-button type="primary" icon="el-icon-plus" @click="copyAll()">复制全部</el-button>
  75. <!-- <el-button type="success" icon="el-icon-edit" @click="update($refs['data-table'].selection[0])"
  76. :disabled="!$refs['data-table'] || $refs['data-table'].selection.length != 1">修改</el-button> -->
  77. <el-button type="danger" icon="el-icon-delete" @click="deleteByIds()">删除</el-button>
  78. <el-button type="warning" icon="el-icon-download" @click="sa.exportExcel()">导出</el-button>
  79. <el-button type="info" icon="el-icon-refresh" @click="sa.f5()">重置</el-button>
  80. <el-button type="danger" icon="el-icon-delete" @click="deleteByStartEnd()">范围删除</el-button>
  81. <el-button type="success" icon="el-icon-view" @click="f5StaData()">统计数据</el-button>
  82. </div>
  83. <!-- ------------- 数据列表 ------------- -->
  84. <el-table class="data-table" ref="data-table" :data="dataList" size="small">
  85. <el-table-column type="selection" width="45px"></el-table-column>
  86. <el-table-column label="请求id" width="110px">
  87. <template slot-scope="s">
  88. <div style="font-weight: bold;">{{s.row.id}}</div>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="请求ip" width="130px">
  92. <template slot-scope="s">
  93. <span class="req-ip">{{(s.row.reqIp)}}</span>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="请求方式" width="100px">
  97. <template slot-scope="s">
  98. <span class="req-type-box">
  99. <b style="background-color: #00A65A;" v-if=" s.row.reqType == 'GET' ">GET</b>
  100. <b style="background-color: #0073B7;" v-else-if=" s.row.reqType == 'POST' ">POST</b>
  101. <b style="background-color: #FF6A00;" v-else>{{s.row.reqType}}</b>
  102. </span>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="请求接口" width="250px">
  106. <template slot-scope="s">
  107. <p class="req-api"><span>{{sa.maxLength(s.row.reqApi)}}</bspan>
  108. </p>
  109. <span class="req-p" @click="seeReqParame(s.row)">{{sa.maxLength(s.row.reqParame, 70)}}</span>
  110. </template>
  111. </el-table-column>
  112. <el-table-column label="请求返回" min-width="370px">
  113. <template slot-scope="s">
  114. <p style="padding-left: 3px;">
  115. <b style="color: green;" v-if="s.row.resCode == 200">{{s.row.resCode}} - {{s.row.resMsg}}</b>
  116. <b style="color: red;" v-else-if="s.row.resCode == 500 || s.row.resCode == 501">{{s.row.resCode}} - {{s.row.resMsg}}</b>
  117. <b style="color: blue;" v-else>{{s.row.resCode}} - {{s.row.resMsg}}</b>
  118. </p>
  119. <p class="req-string" @click="seeResString(s.row)">
  120. {{sa.maxLength(s.row.resString, 70)}}
  121. </p>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="请求账号" width="150px">
  125. <template slot-scope="s">
  126. <p v-if="s.row.userId == 0">userId:&nbsp;&nbsp;&nbsp;0</p>
  127. <p v-else>userId:&nbsp;&nbsp;&nbsp;<el-link @click="sa.alert(s.row.userId)">{{s.row.userId}}</el-link>
  128. </p>
  129. <p v-if="s.row.adminId == 0">adminId:0</p>
  130. <p v-else>adminId:<el-link @click="sa.$page.openAdminInfo(s.row.adminId)">{{s.row.adminId}}</el-link>
  131. </p>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="请求token" width="150px" v-if="!sa.isNull(p.reqToken) ">
  135. <template slot-scope="s">
  136. <div style="width: 130px;">{{s.row.reqToken}}</div>
  137. </template>
  138. </el-table-column>
  139. <el-table-column label="请求时间" width="280px">
  140. <template slot-scope="s">
  141. <p>
  142. 开始:{{sa.forDate(s.row.startTime, 'yyyy-MM-dd HH:mm:ss.ms')}} -
  143. <b>{{sa.isNull(sa.forDate2(s.row.startTime), '无')}}</b>
  144. </p>
  145. <p>
  146. 结束:{{sa.forDate(s.row.endTime, 'yyyy-MM-dd HH:mm:ss.ms')}} -
  147. <b style="color: green;">耗时:{{(s.row.costTime + 0.0) / 1000}}s</b>
  148. </p>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="操作" width="120px">
  152. <template slot-scope="s">
  153. <el-button type="text" @click="copy(s.row)">复制</el-button>
  154. <el-button type="text" @click="del(s.row)" v-if="way == 1">删除</el-button>
  155. </template>
  156. </el-table-column>
  157. </el-table>
  158. <!-- 分页 -->
  159. <div class="page-box">
  160. <el-pagination
  161. background
  162. layout="total, prev, pager, next, sizes, jumper"
  163. :current-page.sync="p.pageNo"
  164. :page-size.sync="p.pageSize"
  165. :total="dataCount"
  166. :page-sizes="[1, 5, 10, 20, 30, 40, 50, 100, 1000]"
  167. @current-change="f5()"
  168. @size-change="f5()">
  169. </el-pagination>
  170. </div>
  171. </div>
  172. </div>
  173. <script>
  174. var app = new Vue({
  175. el: '.vue-box',
  176. data: {
  177. sa: sa,
  178. p: { // 查询参数
  179. pageNo: 1,
  180. pageSize: 10,
  181. id: '',
  182. reqToken: '',
  183. reqIp: '',
  184. reqApi: '',
  185. resCode: '',
  186. userId: '',
  187. adminId: '',
  188. sTime: '',
  189. eTime: '',
  190. sortType: 0
  191. },
  192. way: sa.p('way', 1),
  193. dataCount: 0,
  194. dataList: [], // 数据集合
  195. isNewestSta: false, // 当前是否为最新统计数据
  196. staData: {
  197. cost_time_count: 0, // 总计耗时
  198. }
  199. },
  200. methods: {
  201. // 刷新
  202. f5: function() {
  203. sa.ajax('/sp-admin/SgApilog/getList', sa.removeNull(this.p), function(res) {
  204. this.dataList = res.data; // 数据
  205. this.dataCount = res.dataCount; // 数据总数
  206. sa.f5TableHeight(); // 刷新表格高度
  207. this.isNewestSta = false;
  208. }.bind(this));
  209. },
  210. // 统计数据
  211. f5StaData: function() {
  212. var fn = function() {
  213. var str = '<b>总计请求:' + this.dataCount + ' 次</b><br/>'
  214. + '<b>总计耗时:' + getDuration(this.staData.cost_time_count) + ' </b>';
  215. str = '<big>' + str + '</big>'
  216. layer.alert(str, {title: '统计数据'});
  217. }.bind(this);
  218. if(this.isNewestSta) {
  219. fn()
  220. } else {
  221. sa.ajax('/sp-admin/SgApilog/staBy', sa.removeNull(this.p), function(res) {
  222. this.staData = res.data;
  223. this.isNewestSta = true;
  224. fn();
  225. }.bind(this));
  226. }
  227. },
  228. // 复制
  229. copy: function(data) {
  230. // sa.showIframe('数据详情', 'api-log-info.html?id=' + data.id);
  231. sa.copyText(JSON.stringify(data));
  232. sa.ok2('已成功复制到剪贴板');
  233. },
  234. // 复制全部
  235. copyAll: function() {
  236. // sa.showIframe('数据详情', 'api-log-info.html?id=' + data.id);
  237. sa.copyText(JSON.stringify(this.dataList));
  238. sa.ok2('已成功复制到剪贴板');
  239. },
  240. // 查看:访问参数
  241. seeReqParame: function(data) {
  242. var jsonStr = data.reqParame;
  243. jsonStr = JSON.stringify(JSON.parse(jsonStr), null, "\t");
  244. layer.prompt({
  245. title: '请求参数',
  246. shadeClose: true, // 点击遮罩关闭
  247. formType: 2, // 多行输入
  248. value: jsonStr, // 要显示的字符串
  249. maxlength: 9999999999, // 最大输入字符长度
  250. area: ['600px', '400px'], // 弹窗尺寸
  251. yes: function(index, layero){
  252. layer.close(index); //如果设定了yes回调,需进行手工关闭
  253. }
  254. })
  255. },
  256. // 查看:返回参数
  257. seeResString: function(data) {
  258. var jsonStr = data.resString;
  259. jsonStr = JSON.stringify(JSON.parse(jsonStr), null, "\t");
  260. layer.prompt({
  261. title: '返回参数',
  262. shadeClose: true, // 点击遮罩关闭
  263. formType: 2, // 多行输入
  264. value: jsonStr, // 要显示的字符串
  265. maxlength: 9999999999, // 最大输入字符长度
  266. area: ['600px', '400px'], // 弹窗尺寸
  267. yes: function(index, layero){
  268. layer.close(index); //如果设定了yes回调,需进行手工关闭
  269. }
  270. })
  271. },
  272. // 删除
  273. del: function(data) {
  274. sa.confirm('是否删除,此操作不可撤销', function() {
  275. sa.ajax('/sp-admin/SgApilog/delete?id=' + data.id, function(res) {
  276. sa.arrayDelete(this.dataList, data);
  277. sa.ok('删除成功');
  278. sa.f5TableHeight(); // 刷新表格高度
  279. }.bind(this))
  280. }.bind(this));
  281. },
  282. // 批量删除
  283. deleteByIds: function() {
  284. // 获取选中元素的id列表
  285. let selection = this.$refs['data-table'].selection;
  286. let ids = sa.getArrayField(selection, 'id');
  287. if(selection.length == 0) {
  288. return sa.msg('请至少选择一条数据')
  289. }
  290. // 提交删除
  291. sa.confirm('是否批量删除选中数据?此操作不可撤销', function() {
  292. sa.ajax('/sp-admin/SgApilog/deleteByIds', {ids: ids.join(',')}, function(res) {
  293. sa.arrayDelete(this.dataList, selection);
  294. sa.ok('删除成功');
  295. sa.f5TableHeight(); // 刷新表格高度
  296. }.bind(this))
  297. }.bind(this));
  298. },
  299. // 批量删除
  300. deleteByStartEnd: function() {
  301. sa.showIframe('批量删除', 'api-log-list-delete.html', '600px', '550px');
  302. }
  303. },
  304. created: function() {
  305. this.f5();
  306. sa.onInputEnter(); // 监听表单动作
  307. }
  308. })
  309. function getDuration(my_time) {
  310. var days = my_time / 1000 / 60 / 60 / 24;
  311. var daysRound = Math.floor(days);
  312. var hours = my_time / 1000 / 60 / 60 - (24 * daysRound);
  313. var hoursRound = Math.floor(hours);
  314. var minutes = my_time / 1000 / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
  315. var minutesRound = Math.floor(minutes);
  316. var seconds = my_time / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
  317. seconds = parseInt(seconds);
  318. // console.log('转换时间:', daysRound + '天', hoursRound + '时', minutesRound + '分', seconds + '秒');
  319. // var time = hoursRound + ':' + minutesRound + ':' + seconds
  320. // return time;
  321. if(daysRound >= 1) {
  322. return daysRound + '天' + hoursRound + '小时';
  323. } else if(hoursRound >= 1) {
  324. return hoursRound + '小时' + hoursRound + '分';
  325. } else if(minutesRound >= 1) {
  326. return minutesRound + '分' + seconds + '秒';
  327. } else {
  328. return seconds + '秒';
  329. }
  330. }
  331. </script>
  332. </body>
  333. </html>