api-log-list.html 13 KB

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