table index & delete array item

https://www.iviewui.com/components/table#ZDYLMB


  1. 编辑 row =
  2. {
  3. "keyword": "",
  4. "value": "",
  5. "description": "",
  6. "index": 3,
  7. "operate": [
  8. "edit",
  9. "save",
  10. "cancel"
  11. ],
  12. "isEdit": false,
  13. "_index": 2,
  14. "_rowKey": 49
  15. } 3

demo


  1. <!DOCTYPE html>
  2. <html lang="zh-Hans">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <meta name="author" content="xgqfrms">
  8. <meta name="generator" content="VS code">
  9. <title>vue & iview</title>
  10. <!-- libs -->
  11. <link rel="stylesheet" href="./ivew-3.3.3/iview.css">
  12. <script src="./ivew-3.3.3/vue-2.6.10/vue.min.js"></script>
  13. <script src="./ivew-3.3.3/iview.min.js"></script>
  14. <!-- css -->
  15. <style lang="css">
  16. .audit-common-lable{
  17. width: 120px;
  18. display: inline-block;
  19. text-align: left;
  20. margin: 5px;
  21. }
  22. .audit-common-lable-long{
  23. width: 60px;
  24. display: inline-block;
  25. text-align: right;
  26. }
  27. .audit-common-lable::after,
  28. .audit-common-lable-long::after{
  29. display: inline-block;
  30. content: ":";
  31. width: 0;
  32. border: 1px;
  33. margin: 2px;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <section>
  39. <div id="app">
  40. <template>
  41. <i-row>
  42. <i-col span="24" push="1" style="margin: 5px;">
  43. <span class="audit-common-lable-long">请求方式</span>
  44. <i-switch
  45. style="width: 57px"
  46. size="large"
  47. @on-change="onSwitchChange"
  48. v-model="isGet">
  49. <span slot="open">GET</span>
  50. <span slot="close">POST</span>
  51. </i-switch>
  52. </i-col>
  53. </i-row>
  54. </template>
  55. <template>
  56. <i-row>
  57. <i-col span="24" push="1" style="margin: 5px;">
  58. <span class="audit-common-lable-long">URL</span>
  59. <i-input
  60. v-model="url"
  61. placeholder="请输入 URL"
  62. style="width: 300px"
  63. prefix="md-link"
  64. />
  65. </i-col>
  66. </i-row>
  67. </template>
  68. <template>
  69. <i-row>
  70. <i-col span="24" push="1" style="margin: 5px;">
  71. <span class="audit-common-lable-long">授权方式</span>
  72. <i-select
  73. aria-placeholder="授权方式"
  74. placeholder="请选择授权方式"
  75. style="width: 200px"
  76. v-model="authorization"
  77. @on-change="onChangeSelect(`authorization`)"
  78. :filterable="false"
  79. :clearable="false">
  80. <i-option
  81. v-for="(item, i) in authorizations"
  82. :value="item.value"
  83. :key="i">
  84. {{item.title}}
  85. </i-option>
  86. </i-select>
  87. </i-col>
  88. </i-row>
  89. </template>
  90. <template>
  91. <i-row v-if="authorization==='auth'">
  92. <i-col span="24" push="1" style="margin: 5px;">
  93. <span class="audit-common-lable-long">Username</span>
  94. <i-input
  95. v-model="url"
  96. placeholder="请输入 Username"
  97. style="width: 300px"
  98. prefix="md-contact"
  99. />
  100. </i-col>
  101. <i-col span="24" push="1" style="margin: 5px;">
  102. <span class="audit-common-lable-long">Password</span>
  103. <i-input
  104. v-model="url"
  105. placeholder="请输入 Password"
  106. style="width: 300px"
  107. prefix="md-lock"
  108. />
  109. </i-col>
  110. </i-row>
  111. </template>
  112. <template>
  113. <i-row v-if="authorization==='token'">
  114. <i-col span="24" push="1" style="margin: 5px;">
  115. <span class="audit-common-lable-long">Token</span>
  116. <i-input
  117. v-model="url"
  118. placeholder="请输入 Token!"
  119. style="width: 300px"
  120. prefix="md-lock"
  121. />
  122. </i-col>
  123. </i-row>
  124. </template>
  125. <template v-if="isGet">
  126. <i-row>
  127. <i-col span="18" push="1" style="margin: 5px;">
  128. <span class="audit-common-lable">GET 参数列表</span>
  129. <i-button
  130. @click="addGetParams"
  131. size="small">
  132. + 添加
  133. </i-button>
  134. <!-- :maxHeight="maxGetHeight" -->
  135. <i-table
  136. style="margin: 5px; max-height: 300px; overflow-y: auto;"
  137. :columns="colsGET"
  138. :data="dataGET">
  139. </i-table>
  140. </i-col>
  141. </i-row>
  142. </template>
  143. <template v-else>
  144. <i-row>
  145. <i-col span="23" push="1" style="margin: 5px;">
  146. <span class="audit-common-lable">POST 参数方式</span>
  147. <i-switch
  148. style="width: 57px"
  149. size="large"
  150. @on-change="onSwitchRadioChange"
  151. v-model="isJSON">
  152. <span slot="open">form data</span>
  153. <span slot="close">JSON</span>
  154. </i-switch>
  155. </i-col>
  156. <i-col span="23" push="1" style="margin: 5px;" v-if="isJSON">
  157. <span class="audit-common-lable">参数类型(form data)</span>
  158. <i-table
  159. style="margin: 5px;"
  160. :columns="colsPOST"
  161. :data="dataPOST">
  162. </i-table>
  163. </i-col>
  164. <i-col span="6" push="1" style="margin: 5px;" v-else>
  165. <span class="audit-common-lable">参数类型(JSON)</span>
  166. <i-input
  167. style="margin: 5px; width: 500px;"
  168. placeholder="请输入 JSON String"
  169. v-model="jsonString"
  170. :rows="8"
  171. type="textarea">
  172. </i-input>
  173. </i-col>
  174. </i-row>
  175. </template>
  176. <template>
  177. <i-row>
  178. <i-col span="24" push="1" style="margin: 5px;"></i-col>
  179. <i-col span="2" push="1" style="margin: 5px;">
  180. <i-button
  181. @click="showSave"
  182. size="small"
  183. type="warning">
  184. 保存
  185. </i-button>
  186. </i-col>
  187. <i-col span="2" push="0" style="margin: 5px;">
  188. <i-button
  189. :disabled="!isSaved"
  190. @click="showExecute "
  191. size="small"
  192. type="primary">
  193. 执行
  194. </i-button>
  195. </i-col>
  196. </i-row>
  197. <Modal
  198. v-model="saveModal.visible"
  199. title="确定保存">
  200. <span></span>
  201. <div slot="footer">
  202. <i-button
  203. type="error"
  204. size="large"
  205. :loading="saveModal.loading"
  206. @click="cancelSave">
  207. 取消
  208. </i-button>
  209. <i-button
  210. type="success"
  211. size="large"
  212. :loading="saveModal.loading"
  213. @click="resureSave">
  214. 确定
  215. </i-button>
  216. </div>
  217. </Modal>
  218. <Modal
  219. v-model="executeModal.visible"
  220. @on-ok="resureExecute"
  221. @on-cancel="cancelExecute"
  222. title="确定执行">
  223. <!-- 确定执行 -->
  224. </Modal>
  225. </template>
  226. </div>
  227. </section>
  228. <!-- js -->
  229. <script>
  230. let vueApp = new Vue({
  231. el: "#app",
  232. data: {
  233. saveModal: {
  234. visible: false,
  235. loading: false,
  236. },
  237. executeModal: {
  238. visible: false,
  239. loading: false,
  240. },
  241. isGet: true,
  242. colsGET: [
  243. {
  244. title: "index",
  245. key: "index",
  246. },
  247. {
  248. title: "params.index",
  249. key: "index",
  250. width: 200,
  251. render: (h, params) => {
  252. return h("div", [
  253. h("span", params.index),
  254. ]);
  255. }
  256. },
  257. {
  258. title: "key",
  259. key: "keyword",
  260. render: (h, params) => {
  261. let {
  262. isEdit,
  263. keyword,
  264. } = params.row;
  265. if (isEdit) {
  266. return h("div", [
  267. h("input", {
  268. attrs: {
  269. value: keyword,
  270. placeholder: "请输入 keyword",
  271. },
  272. on: {
  273. change: (e) => {
  274. let value = e.target.value;
  275. // console.log(`e =`, e);
  276. // console.log(`e.target =`, e.target);
  277. console.log(`input value =`, value);
  278. vueApp.updateTempGet(`keyword`, value);
  279. },
  280. }
  281. }, ""),
  282. ]);
  283. } else {
  284. return h("div", [
  285. h("span", keyword),
  286. ]);
  287. }
  288. }
  289. },
  290. {
  291. title: "value",
  292. key: "value",
  293. render: (h, params) => {
  294. let {
  295. isEdit,
  296. value,
  297. } = params.row;
  298. if (isEdit) {
  299. return h("div", [
  300. h("input", {
  301. attrs: {
  302. value: value,
  303. placeholder: "请输入 value",
  304. },
  305. on: {
  306. change: (e) => {
  307. let value = e.target.value;
  308. vueApp.updateTempGet(`value`, value);
  309. },
  310. }
  311. }, ""),
  312. ]);
  313. } else {
  314. return h("div", [
  315. h("span", value),
  316. ]);
  317. }
  318. }
  319. },
  320. {
  321. title: "desc",
  322. key: "description",
  323. render: (h, params) => {
  324. let {
  325. isEdit,
  326. description: desc,
  327. } = params.row;
  328. if (isEdit) {
  329. return h("div", [
  330. h("input", {
  331. attrs: {
  332. value: desc,
  333. placeholder: "请输入描述信息",
  334. },
  335. on: {
  336. change: (e) => {
  337. let value = e.target.value;
  338. vueApp.updateTempGet(`description`, value);
  339. },
  340. }
  341. }, ""),
  342. ]);
  343. } else {
  344. return h("div", [
  345. h("span", desc),
  346. ]);
  347. }
  348. }
  349. },
  350. {
  351. title: "操作",
  352. key: "operate",
  353. render: (h, params) => {
  354. let that = this;
  355. let isEdit = params.row.isEdit;
  356. let edit = params.row.operate[0];
  357. let save = params.row.operate[1];
  358. if (isEdit) {
  359. return h("div", [
  360. h("Icon", {
  361. props: {
  362. name: "person"
  363. }
  364. }),
  365. h("a", {
  366. on: {
  367. click: () => {
  368. vueApp.clickSave(params.index);
  369. },
  370. },
  371. }, save),
  372. ]);
  373. } else {
  374. return h("div", [
  375. h("a", {
  376. on: {
  377. click: () => {
  378. console.log(`编辑 row =\n`, JSON.stringify(params.row, null, 4), params.row.index);
  379. // that.clickEdit(params.row.index);
  380. vueApp.clickEdit(params.row.index);
  381. // that.vueApp.clickEdit(params.row.index);
  382. // that.vueApp.methods.clickEdit(params.row.index);
  383. },
  384. // click: that.clickEdit(params.row.index),
  385. },
  386. }, edit),
  387. h("a", {
  388. on: {
  389. click: () => {
  390. vueApp.clickDelete(params.index);
  391. // vueApp.clickDelete(params.row._index);
  392. // vueApp.clickDelete(params.row.index);
  393. },
  394. },
  395. }, "删除"),
  396. ]);
  397. }
  398. },
  399. },
  400. ],
  401. dataGET: [
  402. {
  403. index: 0,
  404. keyword: "a",
  405. value: "1",
  406. description: "a=1",
  407. operate: ["edit", "save", "cancel"],
  408. isEdit: false,
  409. },
  410. {
  411. index: 1,
  412. keyword: "b",
  413. value: "2",
  414. description: "b=1",
  415. operate: ["edit", "save", "cancel"],
  416. isEdit: false,
  417. },
  418. ],
  419. colsPOST: [],
  420. dataPOST: [],
  421. authorizations: [
  422. {
  423. title: "No Auth",
  424. value: "no",
  425. },
  426. {
  427. title: "Basic Auth",
  428. value: "auth",
  429. },
  430. {
  431. title: "Bearer Token",
  432. value: "token",
  433. },
  434. ],
  435. url: "",
  436. authorization: "no",
  437. isJSON: true,
  438. postType: "form",
  439. jsonString: "",
  440. isSaved: false,
  441. maxGetHeight: 300,
  442. tempGet: {
  443. keyword: "",
  444. value: "",
  445. description: "",
  446. },
  447. tempGetInit: {
  448. keyword: "",
  449. value: "",
  450. description: "",
  451. // index: null,
  452. // operate: ["edit", "save"],
  453. // isEdit: false,
  454. },
  455. },
  456. methods: {
  457. updateTempGet(type = ``, value = ``) {
  458. if(type) {
  459. this.tempGet[type] = value;
  460. }
  461. },
  462. addGetParams() {
  463. let index = this.dataGET.length;
  464. this.dataGET.push({
  465. keyword: "",
  466. value: "",
  467. description: "",
  468. index,
  469. operate: ["edit", "save", "cancel"],
  470. isEdit: false,
  471. });
  472. },
  473. showSave() {
  474. this.saveModal.visible = true;
  475. },
  476. showExecute() {
  477. this.executeModal.visible = true;
  478. },
  479. resureSave() {
  480. this.saveModal.visible = false;
  481. this.isSaved = true;
  482. },
  483. cancelSave() {
  484. this.saveModal.visible = false;
  485. this.isSaved = false;
  486. },
  487. resureExecute() {
  488. this.executeModal.visible = false;
  489. },
  490. cancelExecute() {
  491. this.executeModal.visible = false;
  492. },
  493. onSwitchChange() {
  494. // this.isGet = !this.isGet;
  495. console.log(`value =`, this.isGet);
  496. },
  497. onSwitchRadioChange() {
  498. let value = this.isJSON;
  499. console.log(`isJSON value =`, value);
  500. if (value) {
  501. this.postType = "json";
  502. } else {
  503. this.postType = "form";
  504. }
  505. console.log(`postType = `, this.postType);
  506. },
  507. onChangeSelect (type = ``) {
  508. let value = this[type];
  509. // this.$Message.info(value);
  510. },
  511. onChangeRadio (type = ``) {
  512. let value = this[type];
  513. this.$Message.info(value);
  514. },
  515. onChangeRadioGroup (type = ``) {
  516. let value = this[type];
  517. this.$Message.info(value);
  518. },
  519. clickSave(index = ``) {
  520. if (index !== ``) {
  521. // console.log(`table index =`, index);
  522. this.dataGET[index].isEdit = false;
  523. // temp
  524. let {
  525. keyword,
  526. value,
  527. description,
  528. } = this.tempGet;
  529. this.dataGET[index] = {
  530. keyword,
  531. value,
  532. description,
  533. index: index,
  534. operate: ["edit", "save"],
  535. isEdit: false,
  536. };
  537. }
  538. },
  539. clickEdit(index = ``) {
  540. if (index !== ``) {
  541. // console.log(`table index =`, index);
  542. this.dataGET[index].isEdit = true;
  543. let {
  544. keyword,
  545. value,
  546. description,
  547. } = this.dataGET[index];
  548. this.tempGet = {
  549. keyword,
  550. value,
  551. description,
  552. };
  553. console.log(`tempGet =`, JSON.stringify(this.tempGet, null, 4));
  554. }
  555. },
  556. clickDelete(index = ``) {
  557. if (index !== ``) {
  558. // slice
  559. this.dataGET.splice(index, 1);
  560. this.tempGet = this.tempGetInit;
  561. let newData = this.dataGET || [];
  562. // console.log(`newData =`, JSON.stringify(newData, null, 4));
  563. this.updateDataGETIndex(newData);
  564. }
  565. },
  566. // id ??? index
  567. updateDataGETIndex(data = []) {
  568. let result = [];
  569. result = data.map((item, i) => {
  570. console.log(`item =`, JSON.stringify(item, null, 4));
  571. let obj = Object.assign({}, item, {
  572. index: i,
  573. });
  574. console.log(`obj =`, JSON.stringify(obj, null, 4));
  575. return obj;
  576. });
  577. return result;
  578. },
  579. },
  580. mounted() {
  581. //
  582. },
  583. });
  584. </script>
  585. </body>
  586. </html>

table index & delete array item的更多相关文章

  1. Truncate table、Delete与Drop table的区别

    Truncate table.Delete与Drop table的区别 TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNC ...

  2. SQL中truncate table和delete的区别

    truncate table table_name delete from table_name drop table table_name truncate table在功能上与不带where子句的 ...

  3. Can’t delete list item in Sharepoint2013

         Today,I have meet a very strange error.When I attempt to delete a item from a list,I recieve an ...

  4. truncate table 和delete

    delete table 和 truncate table 使用delete语句删除数据的一般语法格式: delete [from] {table_name.view_name} [where< ...

  5. TRUNCATE TABLE 与 DELETE table 区别

    语法 TRUNCATE TABLE name;参数  TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行. TRUNCATE TABLE ...

  6. Mysql中truncate table和delete语句的区别

    Mysql中的truncate table和delete语句都可以删除表里面所有数据,但是在一些情况下有些不同! 例子: truncate table gag; (1)truncate table删除 ...

  7. oracle impdp时卡死Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

    今天在用impdp导入时,Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX卡在建索引的过程一直不动,也不报错,重试了好几遍还是这样. 后来恍 ...

  8. 小程序重置index,重置item

    重置index,重置item <block wx:for="{{index_data.banner_list}}" wx:for-index="idx" ...

  9. truncate table和delete table 的区别

    truncate table和不带 where 的 detele 功能一样,都是删除表中的所有数据. 但TRUNCATE TABLE 速度更快,占用的日志更少,这是因为 TRUNCATE TABLE ...

随机推荐

  1. P1145 约瑟夫 W(模拟)

    暴力+模拟 #include<iostream> #include<cstring> using namespace std; int ans, k, k2; ]; bool ...

  2. Mqtt用户认证

    http://emqtt.com/docs/v2/guide.html 1默认是匿名认证,不用输入用户名和密码,直接可连接 2如何开启用户名和密码认证模式 2-1关闭匿名认证 在你的MQTT安装目录下 ...

  3. js Ajax 请求返回

    1.后台正常返回值 2.后台异常返回值 一 后台正常返回值 二.后台异常返回 场景1:报错 场景2:登录超时,这种场景,需要考虑

  4. A2D JS框架 - loadScript实现

    其实这个功能比较小,本着自己造轮子的优良传统....就自己造一个好了 <head> <title></title> <script src="A2D ...

  5. [C#] LINQ之Join与GroupJoin

    声明:本文为www.cnc6.cn原创,转载时请注明出处,谢谢! 一.编写Person与City类,如下: class Person { public int CityID { set; get; } ...

  6. Windows Community Toolkit 3.0 - Gaze Interaction

    概述 Gaze Input & Tracking - 也就是视觉输入和跟踪,是一种和鼠标/触摸屏输入非常不一样的交互方式,利用人类眼球的识别和眼球方向角度的跟踪,来判断人眼的目标和意图,从而非 ...

  7. 不容错过的超赞项目管理PPT

    不容错过的超赞项目管理PPT(转载) 大公司的一个好处,是各个领域都有牛人,可以为你提供经验分享交流.腾讯庞大的培训体系更是保证了:如果你想学点什么东西,你总可以学到.腾讯内部资源30页PPT曝光 — ...

  8. 【评分】Alpha 事后诸葛亮(团队)

    [评分]Alpha 事后诸葛亮(团队) 总结 按时交 - 有分 晚交 - 0分 迟交一周以上 - 倒扣本次作业分数 抄袭 - 倒扣本次作业分数 本次作业都是以问答形式进行,大部分同学在回答问题方面都一 ...

  9. Graph Without Long Directed Paths CodeForces - 1144F (dfs染色)

    You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self ...

  10. CentOS 7.2 yum安装LAMP环境

    https://www.linuxidc.com/Linux/2016-11/136766.htm 详见以上链接,用yum安装方便省事. 尤其注意,mysql数据要设置远程连接.