default-setting.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>sa-doc 全局默认参数设置</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="./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="./sa.js"></script>
  15. <style type="text/css">
  16. .vue-box{max-width: 1000px; margin: auto;}
  17. /* api-url盒子 */
  18. .ajax-api-box{width: 100%;}
  19. .c-panel .ajax-api-box .el-input{width: calc(100% - 200px);}
  20. /* type */
  21. .ajax-type,
  22. .ajax-type .el-input,
  23. .ajax-type .el-input__inner{width: 100px !important; text-align: center;
  24. font-weight: bold; background-color: #409EFF; color: #FFF; border-color: #409EFF !important; border-radius: 4px;}
  25. .ajax-type{margin-right: 5px; }
  26. /* 参数盒子 */
  27. .header-box .el-table__header-wrapper{height: 0px;}
  28. .body-box .el-table__header-wrapper{height: 0px;}
  29. .el-table td{border: 0px !important;}
  30. .el-table::before{background-color: rgba(0,0,0,0)}
  31. .add-btn{padding: 5px 15px; margin-left: 10px; display: inline-block;}
  32. .add-btn .el-link--inner{position: relative; top: -1px;}
  33. .el-table__empty-block{height: 0px !important; display: none;}
  34. .el-textarea__inner{padding: 10px 15px; color: inherit;}
  35. </style>
  36. </head>
  37. <body>
  38. <div style="margin-top: -1em;" title="防止margin向下击穿"><br></div>
  39. <div class="vue-box" style="display: none;" :style="'display: block;'">
  40. <div class="c-panel">
  41. <div class="c-title">
  42. <span>参数说明</span>
  43. </div>
  44. <div>
  45. <span style="color: #666; margin-left: 10px;">全局默认参数,会在每个测试接口里自动加载出来</span>
  46. </div>
  47. <!--------------- 请求地址 --------------->
  48. <div class="c-title" style="margin-top: 20px;">
  49. <span>全局设置</span>
  50. <br>
  51. <el-checkbox v-model="isCookie">发送Cookie</el-checkbox>
  52. </div>
  53. <!--------------- header 参数 --------------->
  54. <div class="c-title" style="margin-top: 20px;">
  55. <span>全局 header 参数</span>
  56. <el-link class="add-btn" type="primary" icon="el-icon-plus" @click="headerListAdd()">添加</el-link>
  57. </div>
  58. <div class="header-box">
  59. <el-table :data="headerList" size="mini" ref="headerTable">
  60. <el-table-column label="Name">
  61. <template slot-scope="s">
  62. <el-input size="small" v-model="s.row.name"></el-input>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="Value">
  66. <template slot-scope="s">
  67. <el-input size="small" v-model="s.row.value"></el-input>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="操作" width="100px">
  71. <template slot-scope="s">
  72. <el-button class="c-btn" type="danger" icon="el-icon-close" @click="sa.arrayDelete(headerList, s.row)" tabindex="-1">删除</el-button>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. </div>
  77. <!--------------- body 参数 --------------->
  78. <div class="c-title" style="margin-top: 20px;">
  79. <span>全局 body 参数</span>
  80. <el-link class="add-btn" type="primary" icon="el-icon-plus" @click="bodyListAdd()">添加</el-link>
  81. </div>
  82. <div class="body-box">
  83. <el-table :data="bodyList" size="mini" ref="bodyTable">
  84. <el-table-column label="Name">
  85. <template slot-scope="s">
  86. <el-input size="small" v-model="s.row.name"></el-input>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="Value">
  90. <template slot-scope="s">
  91. <el-input size="small" v-model="s.row.value" :placeholder="s.row.tips"></el-input>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="操作" width="100px">
  95. <template slot-scope="s">
  96. <el-button class="c-btn" type="danger" icon="el-icon-close" @click="sa.arrayDelete(bodyList, s.row)">删除</el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. </div>
  101. <div class="c-title" style="margin-top: 20px;">操作</div>
  102. <div class="c-item ajax-api-box" style="min-width: 0px; padding-right: 5px;">
  103. <el-button size="small" type="primary" icon="el-icon-plus" @click="save()">保存</el-button>
  104. <el-button size="small" icon="el-icon-close" @click="sa.closeCurrIframe()">关闭</el-button>
  105. <span class="c-remark"></span>
  106. </div>
  107. </div>
  108. </div>
  109. <script>
  110. var app = new Vue({
  111. el: '.vue-box',
  112. data: {
  113. isCookie: false,
  114. headerList: [], // headr数据集合
  115. bodyList: [], // body数据集合
  116. },
  117. methods: {
  118. // header添加参数
  119. headerListAdd: function(header) {
  120. header = header || {name: '', value: '', tips: ''};
  121. this.headerList.push(header);
  122. this.f5_tabindex();
  123. },
  124. // body添加参数
  125. bodyListAdd: function(body) {
  126. body = body || {name: '', value: '', tips: ''};
  127. this.bodyList.push(body);
  128. this.f5_tabindex();
  129. },
  130. // 保存
  131. save: function() {
  132. // 写入本地缓存
  133. localStorage.setItem('isCookieCC', this.isCookie + "");
  134. localStorage.setItem('headerListCC', JSON.stringify(this.headerList));
  135. localStorage.setItem('bodyListCC', JSON.stringify(this.bodyList));
  136. sa.ajax2('asd', function() {
  137. // sa.ok2('保存成功');
  138. sa.alert('保存成功',function() {
  139. sa.closeCurrIframe();
  140. })
  141. }, {msg: '正在保存...'})
  142. },
  143. // 设置一下 tabindex
  144. f5_tabindex: function() {
  145. this.$nextTick(function() {
  146. $('.el-checkbox__original').attr('tabindex', -1);
  147. })
  148. },
  149. // 从本地缓存中加载参数
  150. init: function() {
  151. try{
  152. // 是否发送cookie
  153. var isCookieCC = localStorage.getItem('isCookieCC');
  154. this.isCookie = isCookieCC === "true";
  155. // 加载默认header参数
  156. var headerListCC = localStorage.getItem('headerListCC');
  157. if(headerListCC && headerListCC != '') {
  158. headerListCC = JSON.parse(headerListCC);
  159. headerListCC.forEach(function(item) {
  160. if(item.name == null || item.name == '') {
  161. return;
  162. }
  163. this.headerListAdd(item);
  164. }.bind(this))
  165. }
  166. // 加载默认body参数
  167. var bodyListCC = localStorage.getItem('bodyListCC');
  168. if(bodyListCC && bodyListCC != '') {
  169. bodyListCC = JSON.parse(bodyListCC);
  170. bodyListCC.forEach(function(item) {
  171. if(item.name == null || item.name == '') {
  172. return;
  173. }
  174. this.bodyListAdd(item);
  175. }.bind(this))
  176. }
  177. }catch(e){
  178. console.error(e);
  179. }
  180. }
  181. },
  182. created: function() {
  183. // this.f5();
  184. },
  185. mounted: function() {
  186. this.init();
  187. }
  188. })
  189. </script>
  190. </body>
  191. </html>