listComponent.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div>
  3. <div style="width: 100%;height: 40px;">
  4. <div style="margin: 0 12px;float: left;">
  5. <el-button
  6. v-for="item in customButton"
  7. :type="item.type"
  8. :size="item.size"
  9. :icon="item.icon"
  10. :disabled="item.disabled"
  11. @click="buttonList(item)">
  12. {{ item.name }}
  13. </el-button>
  14. </div>
  15. <div class="tabSetting">
  16. <div style="margin-left:10px;float: right">
  17. <el-button
  18. icon="el-icon-setting"
  19. size="mini"
  20. circle
  21. @click="showSetting = !showSetting"
  22. ></el-button>
  23. </div>
  24. <right-toolbar
  25. @showSearch="showSearch"
  26. @queryTable="getList"
  27. ></right-toolbar>
  28. </div>
  29. </div>
  30. <el-table
  31. :data="tableData"
  32. style="width: 100%"
  33. @selection-change="handleSelectionChange"
  34. :row-class-name="rowClassName"
  35. >
  36. <el-table-column
  37. v-for="(item,index) in setRowList"
  38. :key="index"
  39. :prop="item.label"
  40. :label="item.name"
  41. :width="item.width"
  42. align="center"
  43. >
  44. <template slot-scope="scope">
  45. <span v-if="item.name === '操作'">
  46. <span v-if="item.operation == 1">
  47. <el-button type="text" @click="viewMethod(scope)">查看</el-button>
  48. <el-button type="text" @click="modification(scope)">修改</el-button>
  49. <el-button type="text" @click="deletion(scope)">删除</el-button>
  50. </span>
  51. <span v-if="item.operation == 2">
  52. <el-button type="text" @click="deleteRow(scope.$index, tableData)">移除</el-button>
  53. </span>
  54. </span>
  55. <span v-else-if="item.changeable">
  56. <el-select v-if="item.changeable == 1" v-model="scope.row[item.label]" slot="prepend" placeholder="请选择">
  57. <el-option
  58. v-for="(item,index) in item.data"
  59. :key="index"
  60. :label="item.label"
  61. :value="item.value"
  62. ></el-option>
  63. </el-select>
  64. <el-input v-if="item.changeable == 2" v-model="scope.row[item.label]" placeholder="请输入内容" :onkeyup="item.onabort"></el-input>
  65. <el-date-picker
  66. v-if="item.changeable == 3"
  67. v-model="scope.row[item.label]"
  68. type="date"
  69. placeholder="选择日期"
  70. >
  71. </el-date-picker>
  72. </span>
  73. <span v-else>{{ scope.row[item.label] }}</span>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <el-dialog title="自定义列显示" :visible.sync="showSetting" width="700px">
  78. <div>配置排序列数据(拖动调整顺序)</div>
  79. <div style="margin-left: 17px">
  80. <el-checkbox
  81. v-model="allCheck"
  82. label="全选"
  83. @change="allChecked"
  84. ></el-checkbox>
  85. </div>
  86. <div style="padding: 4px; display: flex; justify-content: center">
  87. <draggable
  88. v-model="setRowList"
  89. group="site"
  90. animation="300"
  91. @start="onStart"
  92. @end="onEnd"
  93. handle=".indraggable"
  94. >
  95. <transition-group>
  96. <div
  97. v-for="item in setRowList"
  98. :key="item.surface"
  99. class="listStyle"
  100. >
  101. <div style="width: 500px" class="indraggable">
  102. <div class="progress" :style="{ width: item.width + 'px' }">
  103. <el-checkbox
  104. :label="item.name"
  105. v-model="item.checked"
  106. :true-label="0"
  107. :false-label="1"
  108. >{{ item.name }}
  109. </el-checkbox>
  110. </div>
  111. </div>
  112. <el-input-number
  113. v-model.number="item.width"
  114. controls-position="right"
  115. :min="1"
  116. :max="500"
  117. size="mini"
  118. ></el-input-number>
  119. </div>
  120. </transition-group>
  121. </draggable>
  122. </div>
  123. <span slot="footer" class="dialog-footer">
  124. <el-button @click="showSetting = false">取 消</el-button>
  125. <el-button @click="delRow" type="danger">重 置</el-button>
  126. <el-button type="primary" @click="save()">确 定</el-button>
  127. </span>
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <script>
  132. import { addSet, resetModule } from "@/api/system/set";
  133. import Cookies from "js-cookie";
  134. export default {
  135. name: 'listComponent',
  136. props: ['tableData', 'listStyle','queryList','customButton'],
  137. data() {
  138. return {
  139. setRowList:this.queryList.columnList.length !== 0?this.queryList.columnList:this.listStyle,
  140. showSetting: false,
  141. allCheck: false,
  142. }
  143. },
  144. created() {
  145. console.log(this.listStyle)
  146. console.log(this.queryList)
  147. console.log(this.queryList.columnList.length)
  148. },
  149. methods: {
  150. //行号设置
  151. rowClassName({row, rowIndex}) {
  152. console.log(row,rowIndex)
  153. //把每一行的索引放进row.id
  154. row.fLineNumber = rowIndex+1;
  155. console.log(row.fLineNumber)
  156. },
  157. //列设置全选
  158. allChecked() {
  159. if (this.allCheck == true) {
  160. this.setRowList.map((e) => {
  161. return (e.checked = 0);
  162. });
  163. } else {
  164. this.setRowList.map((e) => {
  165. return (e.checked = 1);
  166. });
  167. }
  168. },
  169. //开始拖拽事件
  170. onStart() {
  171. this.drag = true;
  172. },
  173. //拖拽结束事件
  174. onEnd() {
  175. this.drag = false;
  176. },
  177. //保存列设置
  178. save() {
  179. this.showSetting = false;
  180. this.data = {
  181. tableName: this.queryList.tableName,
  182. userId: Cookies.get("userName"),
  183. sysTableSetList: this.setRowList,
  184. };
  185. addSet(this.data).then((res) => {
  186. if (res.code == 200) {
  187. this.showSetting = false;
  188. this.getRowList = this.setRowList.filter((e) => e.checked == 0);
  189. }
  190. });
  191. },
  192. //自定义列
  193. delRow() {
  194. this.data = {
  195. tableName: this.queryList.tableName,
  196. userId: Cookies.get("userName"),
  197. };
  198. resetModule(this.data).then((res) => {
  199. if (res.code == 200) {
  200. this.showSetting = false;
  201. this.setRowList = this.listStyle;
  202. console.log(this.getRowList)
  203. }
  204. });
  205. },
  206. showSearch(){
  207. this.$emit('showSearch')
  208. },
  209. //刷新按钮
  210. getList(){
  211. this.$emit('getList')
  212. },
  213. //所有按钮
  214. buttonList(row){
  215. this.$emit('buttonList', row)
  216. },
  217. //查看
  218. viewMethod(scope) {
  219. this.$emit('see', scope)
  220. },
  221. //修改
  222. modification(scope){
  223. this.$emit('modify', scope)
  224. },
  225. //删除
  226. deletion(scope){
  227. this.$emit('deletion', scope)
  228. },
  229. //移出
  230. deleteRow(index, rows) {
  231. rows.splice(index, 1);
  232. },
  233. //选择
  234. handleSelectionChange(selection){
  235. this.$emit('selectionbox', selection)
  236. }
  237. }
  238. }
  239. </script>
  240. <style scoped>
  241. .listStyle {
  242. display: flex;
  243. border-top: 1px solid #dcdfe6;
  244. border-left: 1px solid #dcdfe6;
  245. border-right: 1px solid #dcdfe6;
  246. }
  247. .listStyle:last-child {
  248. border-bottom: 1px solid #dcdfe6;
  249. }
  250. .progress {
  251. display: flex;
  252. align-items: center;
  253. padding: 2px;
  254. background-color: rgba(0, 0, 0, 0.05);
  255. height: 100%;
  256. }
  257. </style>