index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="execution">
  19. <basic-container>
  20. <avue-crud ref="crud"
  21. :data="tableData"
  22. :option="tableOption"
  23. @row-update="handleUpdate"
  24. @row-save="handleSave"
  25. @row-del="handleDel">
  26. <template slot-scope="props"
  27. slot="expand">
  28. <el-form label-position="left"
  29. inline
  30. class="demo-table-expand">
  31. <el-form-item label="姓名">
  32. <span>{{ props.row.name }}</span>
  33. </el-form-item>
  34. <el-form-item label="用户名">
  35. <span>{{ props.row.username }}</span>
  36. </el-form-item>
  37. <el-form-item label="地址">
  38. <a :href="props.row.address"
  39. target="_blank">{{props.row.address}}</a>
  40. </el-form-item>
  41. <el-form-item label="项目地址">
  42. <a :href="props.row.git"
  43. target="_blank">{{props.row.git}}</a>
  44. </el-form-item>
  45. <el-form-item label="stars">
  46. <a :href='props.row.address'
  47. target="_blank">
  48. <img :src="props.row.stars"
  49. alt='star'/>
  50. </a>
  51. </el-form-item>
  52. </el-form>
  53. </template>
  54. <template slot-scope="scope"
  55. slot="username">
  56. <el-tag>{{scope.row.username}}</el-tag>
  57. </template>
  58. <template slot-scope="scope"
  59. slot="stars">
  60. <a :href='scope.row.git'
  61. target="_blank">
  62. <img :src="scope.row.stars"
  63. alt='star'/>
  64. </a>
  65. </template>
  66. <template slot-scope="scope"
  67. slot="address">
  68. <a :href="scope.row.git"
  69. target="_blank">{{scope.row.address}}</a>
  70. </template>
  71. </avue-crud>
  72. </basic-container>
  73. </div>
  74. </template>
  75. <script>
  76. import {tableOption} from '@/const/crud/option'
  77. import {tableData} from '@/const/crud/data'
  78. export default {
  79. name: 'crud',
  80. data() {
  81. return {
  82. tableData: tableData,
  83. tableOption: tableOption
  84. }
  85. },
  86. mounted: function () {
  87. },
  88. methods: {
  89. handleDel: function (row, index) {
  90. var _this = this
  91. this.$confirm('是否确认删除序号为' + row.username, '提示', {
  92. confirmButtonText: '确定',
  93. cancelButtonText: '取消',
  94. type: 'warning'
  95. })
  96. .then(function () {
  97. _this.tableData.splice(index, 1)
  98. _this.$message({
  99. showClose: true,
  100. message: '删除成功',
  101. type: 'success'
  102. })
  103. })
  104. .catch(function (err) {
  105. })
  106. },
  107. /**
  108. * @title 数据更新
  109. * @param row 为当前的数据
  110. * @param index 为当前更新数据的行数
  111. * @param done 为表单关闭函数
  112. *
  113. **/
  114. handleUpdate: function (row, index, done) {
  115. this.tableData.splice(index, 1, Object.assign({}, row))
  116. this.$message({
  117. showClose: true,
  118. message: '修改成功',
  119. type: 'success'
  120. })
  121. done()
  122. },
  123. /**
  124. * @title 数据添加
  125. * @param row 为当前的数据
  126. * @param done 为表单关闭函数
  127. *
  128. **/
  129. handleSave: function (row, done) {
  130. this.tableData.push(Object.assign({}, row))
  131. this.$message({
  132. showClose: true,
  133. message: '添加成功',
  134. type: 'success'
  135. })
  136. done()
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .demo-table-expand {
  143. font-size: 0;
  144. }
  145. .demo-table-expand label {
  146. width: 90px;
  147. color: #99a9bf;
  148. }
  149. .demo-table-expand .el-form-item {
  150. margin-right: 0;
  151. margin-bottom: 0;
  152. width: 50%;
  153. }
  154. </style>