api-log-list.html 16 KB

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