elementui表格的列拖拽及动态显示列实现

淡淡的烟草味﹌ 2023-06-07 10:57 454阅读 0赞
  1. 安装Sortable

    npm install sortablejs —save

  2. 引入Sortable

    import Sortable from ‘sortablejs’

  3. 添加列拖拽方法

    //列拖拽
    columnDrop() {

    1. const wrapperTr = document.querySelector('.el-table__header-wrapper tr')
    2. this.sortable = Sortable.create(wrapperTr, {
    3. animation: 180,
    4. delay: 0,
    5. onEnd: evt => {
    6. const oldItem = this.dropCol[evt.oldIndex]
    7. this.dropCol.splice(evt.oldIndex, 1)
    8. this.dropCol.splice(evt.newIndex, 0, oldItem)
    9. }
    10. })

    }

  4. 拼装表单列数据

    getDropCol(){

    1. if(this.orders&&this.orders.hasOwnProperty('device')){
    2. let data=JSON.parse(this.orders['device'])
    3. return data
    4. }
    5. return this.getCol()
    6. },
    7. getCol() {
    8. let allCols = [
    9. {prop: "select", label: "选择"},
    10. {prop: "index", label: "序号"},
    11. {prop: "name", label: "设备型号"},
    12. {prop: "cluster.name", label: "集群",type:"cluster"},
    13. {prop: "type", label: "服务器分类"},
    14. {prop: "sn", label: "设备序列号"},
    15. {prop: "manageIp", label: "管理网"},
    16. {prop: "illoIp", label: "ILLO地址"},
    17. {prop: "period", label: "期数"},
    18. {prop: "position", label: "机架位置"},
    19. {prop: "publicIp", label: "公网"},
    20. {prop: "cn2Ip", label: "CN2"},
    21. {prop: "outIp", label: "存储外网"},
    22. {prop: "systemVersion", label: "系统版本"},
    23. {prop: "osVersion", label: "内核版本"},
    24. {prop: "use", label: "用途"},
    25. {prop: "deliveryDate", label: "交付日期",type:"date"},
    26. {prop: "useUser", label: "申请人"},
    27. {prop: "tag", label: "项目名称"},
    28. {prop: "remarks", label: "备注"},
    29. {prop: "computerPosition", label: "机房位置"},
    30. ]
    31. if (this.cols && this.cols.hasOwnProperty('device')) {
    32. if (this.cols['device'] === "") {
    33. return allCols;
    34. }
    35. let str = this.cols['device'];
    36. let data = this.utils.str2Arr(str);
    37. let result=[]
    38. result.push({prop: "select", label: "选择"})
    39. result.push({prop: "index", label: "序号"})
    40. data.forEach(function (item) {
    41. allCols.forEach(function (col) {
    42. if (col.prop === item) {
    43. result.push(col);
    44. }
    45. })
    46. })
    47. return result;
    48. } else {
    49. return allCols;
    50. }
    51. },

注:我这里因为配合后端保存了顺序而且支持了列是否显示的功能,所以需要检索this.orders,如果不需要可以直接使用this.gelCol()

  1. 初始化页面时,初始化列数据

    mounted() {

    1. this.columnDrop()
    2. this.col=this.getDropCol();
    3. this.dropCol=this.getDropCol();
    4. },
  2. v-for生成表格

    <el-table-column

    1. type="selection"
    2. width="55">
    3. </el-table-column>
    4. <el-table-column type="index" align="center" width="50">
    5. </el-table-column>
    6. <el-table-column v-for="(item, index) in col"
    7. v-if="col[index].prop!=='select'&&col[index].prop!=='index'"
    8. align="center"
    9. show-overflow-tooltip
    10. width="200px"
    11. :key="`col_${index}`"
    12. :prop="dropCol[index].prop"
    13. :label="item.label">
    14. <template slot-scope="scope">
    15. <span>{

    { !dropCol[index].type?scope.row[dropCol[index].prop]:getValue(scope.row,dropCol[index].type),dropCol[index].prop }}

    1. </template>
    2. </el-table-column>
    3. <el-table-column label="操作" align="center" fixed="right" width="200" class-name="small-padding fixed-width">
    4. <template slot-scope="scope">
    5. <el-dropdown trigger="hover">
    6. <span class="el-dropdown-link">
    7. 操作菜单<i class="el-icon-arrow-down el-icon--right"></i>
    8. </span>
    9. <el-dropdown-menu slot="dropdown">
    10. <el-dropdown-item class="el-dropdown-link" @click.native="cpuInfo(scope.row)">硬件信息</el-dropdown-item>
    11. <!-- <el-dropdown-item class="el-dropdown-link" @click.native="memoryInfo(scope.row)">内存信息</el-dropdown-item>-->
    12. <!-- <el-dropdown-item class="el-dropdown-link" @click.native="nicInfo(scope.row)">网卡信息</el-dropdown-item>-->
    13. <!-- <el-dropdown-item class="el-dropdown-link" @click.native="diskInfo(scope.row)">硬盘信息</el-dropdown-item>-->
    14. <el-dropdown-item class="el-dropdown-link" @click.native="historyInfo(scope.row)">历史变更</el-dropdown-item>
    15. <el-dropdown-item class="el-dropdown-link" @click.native="editDevice(scope.row)">编辑资产</el-dropdown-item>
    16. <el-dropdown-item class="el-dropdown-link" @click.native="deleteDevice(scope.row)">删除资产</el-dropdown-item>
    17. </el-dropdown-menu>
    18. </el-dropdown>
    19. </template>
    20. </el-table-column>
    21. </el-table>

我这里配合type来对特殊字段进行了处理,使用了getValue的方法实现的,好像也可以用v-if来做(毕竟不是专业前端,随便来了= =)

整页代码(非纯前端,有些粗糙见谅= =):

  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-input v-model="listQuery.cluster" clearable placeholder="请输入所属集群" style="width: 200px;"
  5. class="filter-item"
  6. @keyup.enter.native="handleFilter"/>
  7. <el-input v-model="listQuery.outIp" clearable placeholder="请输入存储外网IP" style="width: 200px;"
  8. class="filter-item"
  9. @keyup.enter.native="handleFilter"/>
  10. <el-button type="primary" plain @click="handleFilter" class="filter-item">搜索</el-button>
  11. <el-button type="primary" plain @click="createDevice" class="filter-item">创建资产</el-button>
  12. <el-button type="primary" plain @click="changeCols" class="filter-item">修改显示列</el-button>
  13. <el-button type="primary" plain @click="addHs" class="filter-item">添加历史变更</el-button>
  14. <el-button type="primary" plain @click="saveOrder" class="filter-item">保存显示顺序</el-button>
  15. <el-upload
  16. :action="deviceUrl"
  17. :show-file-list="false"
  18. :on-success="handleAvatarSuccess"
  19. style="margin-top: 5px;"
  20. >
  21. <el-button size="small" type="primary">导入</el-button>
  22. </el-upload>
  23. </div>
  24. <el-table
  25. v-loading="listLoading"
  26. :data="list"
  27. border
  28. fit
  29. size="mini"
  30. :row-class-name="rowClassName"
  31. :cell-class-name="cellClassName"
  32. highlight-current-row
  33. style="width: 100%;margin-top: 20px"
  34. @selection-change="handleSelectionChange"
  35. >
  36. <el-table-column
  37. type="selection"
  38. width="55">
  39. </el-table-column>
  40. <el-table-column type="index" align="center" width="50">
  41. </el-table-column>
  42. <el-table-column v-for="(item, index) in col"
  43. v-if="col[index].prop!=='select'&&col[index].prop!=='index'"
  44. align="center"
  45. show-overflow-tooltip
  46. width="200px"
  47. :key="`col_${index}`"
  48. :prop="dropCol[index].prop"
  49. :label="item.label">
  50. <template slot-scope="scope">
  51. <span>{
  52. { !dropCol[index].type?scope.row[dropCol[index].prop]:getValue(scope.row,dropCol[index].type),dropCol[index].prop }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="操作" align="center" fixed="right" width="200" class-name="small-padding fixed-width">
  56. <template slot-scope="scope">
  57. <el-dropdown trigger="hover">
  58. <span class="el-dropdown-link">
  59. 操作菜单<i class="el-icon-arrow-down el-icon--right"></i>
  60. </span>
  61. <el-dropdown-menu slot="dropdown">
  62. <el-dropdown-item class="el-dropdown-link" @click.native="cpuInfo(scope.row)">硬件信息</el-dropdown-item>
  63. <!-- <el-dropdown-item class="el-dropdown-link" @click.native="memoryInfo(scope.row)">内存信息</el-dropdown-item>-->
  64. <!-- <el-dropdown-item class="el-dropdown-link" @click.native="nicInfo(scope.row)">网卡信息</el-dropdown-item>-->
  65. <!-- <el-dropdown-item class="el-dropdown-link" @click.native="diskInfo(scope.row)">硬盘信息</el-dropdown-item>-->
  66. <el-dropdown-item class="el-dropdown-link" @click.native="historyInfo(scope.row)">历史变更</el-dropdown-item>
  67. <el-dropdown-item class="el-dropdown-link" @click.native="editDevice(scope.row)">编辑资产</el-dropdown-item>
  68. <el-dropdown-item class="el-dropdown-link" @click.native="deleteDevice(scope.row)">删除资产</el-dropdown-item>
  69. </el-dropdown-menu>
  70. </el-dropdown>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
  75. @pagination="getList"/>
  76. <el-dialog title="Device管理" :visible.sync="dialogFormVisible" :close-on-click-modal=false>
  77. <el-form :model="temp" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  78. <el-form-item label="集群" prop="cluster">
  79. <el-select v-model="temp.clusterId" placeholder="请选择">
  80. <el-option
  81. v-for="item in clusterList"
  82. :key="item.id"
  83. :label="item.name"
  84. :value="item.id">
  85. </el-option>
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item label="设备型号" prop="name">
  89. <el-input v-model="temp.name"></el-input>
  90. </el-form-item>
  91. <el-form-item label="期数" prop="period">
  92. <el-input v-model="temp.period"></el-input>
  93. </el-form-item>
  94. <el-form-item label="管理网" prop="manageIp">
  95. <el-input v-model="temp.manageIp"></el-input>
  96. </el-form-item>
  97. <el-form-item label="ILLO地址" prop="cluster">
  98. <el-input v-model="temp.illoIp"></el-input>
  99. </el-form-item>
  100. <el-form-item label="交付日期" prop="deliveryDate">
  101. <el-date-picker
  102. v-model="temp.deliveryDate"
  103. type="date"
  104. placeholder="选择日期">
  105. </el-date-picker>
  106. </el-form-item>
  107. <el-form-item label="服务器分类" prop="type">
  108. <el-input v-model="temp.type"></el-input>
  109. </el-form-item>
  110. <el-form-item label="设备类型" prop="deviceType">
  111. <el-select v-model="temp.deviceType" placeholder="请选择">
  112. <el-option
  113. v-for="item in deviceTypeList"
  114. :key="item.deviceType"
  115. :label="item.nameZh"
  116. :value="item.deviceType">
  117. </el-option>
  118. </el-select>
  119. </el-form-item>
  120. <el-form-item label="设备序列号" prop="sn">
  121. <el-input v-model="temp.sn"></el-input>
  122. </el-form-item>
  123. <el-form-item label="项目名称" prop="tag">
  124. <tag-select type="program" :value.sync="temp.tag"></tag-select>
  125. </el-form-item>
  126. <el-form-item label="机架位置" prop="position">
  127. <el-input v-model="temp.position"></el-input>
  128. </el-form-item>
  129. <el-form-item label="机房位置" prop="computerPosition">
  130. <el-input v-model="temp.computerPosition"></el-input>
  131. </el-form-item>
  132. <el-form-item label="公网" prop="publicIp">
  133. <el-input v-model="temp.publicIp"></el-input>
  134. </el-form-item>
  135. <el-form-item label="存储外网" prop="inIp">
  136. <el-input v-model="temp.outIp"></el-input>
  137. </el-form-item>
  138. <el-form-item label="CN2" prop="cn2Ip">
  139. <el-input v-model="temp.cn2Ip"></el-input>
  140. </el-form-item>
  141. <el-form-item label="系统版本" prop="systemVersion">
  142. <el-input v-model="temp.systemVersion"></el-input>
  143. </el-form-item>
  144. <el-form-item label="内核版本" prop="osVersion">
  145. <el-input v-model="temp.osVersion"></el-input>
  146. </el-form-item>
  147. <el-form-item label="用途" prop="use">
  148. <el-input v-model="temp.use"></el-input>
  149. </el-form-item>
  150. <el-form-item label="备注" prop="remarks">
  151. <el-input v-model="temp.remarks"></el-input>
  152. </el-form-item>
  153. </el-form>
  154. <div slot="footer" class="dialog-footer">
  155. <el-button type="primary" @click="saveDevice('ruleForm')">提交</el-button>
  156. <el-button @click="resetDeviceForm('ruleForm')">取消</el-button>
  157. </div>
  158. </el-dialog>
  159. <el-dialog title="硬件信息" :visible.sync="CPUVisible" width="80%">
  160. <el-collapse v-model="collapse">
  161. <el-collapse-item title="CPU信息" name="1">
  162. <cpu :device_type.sync="deviceType"></cpu>
  163. </el-collapse-item>
  164. <el-collapse-item title="内存信息" name="2">
  165. <memory :device_type.sync="deviceType"></memory>
  166. </el-collapse-item>
  167. <el-collapse-item title="硬盘信息" name="3">
  168. <disk :device_type.sync="deviceType"></disk>
  169. </el-collapse-item>
  170. <el-collapse-item title="网卡信息" name="4">
  171. <nic :device_type.sync="deviceType"></nic>
  172. </el-collapse-item>
  173. </el-collapse>
  174. </el-dialog>
  175. <!-- <el-dialog title="内存信息" :visible.sync="MemoryVisible" width="80%">-->
  176. <!-- <memory :device_type.sync="deviceType"></memory>-->
  177. <!-- </el-dialog>-->
  178. <!-- <el-dialog title="硬盘信息" :visible.sync="DiskVisible" width="80%">-->
  179. <!-- <disk :device_type.sync="deviceType"></disk>-->
  180. <!-- </el-dialog>-->
  181. <!-- <el-dialog title="网卡信息" :visible.sync="NicVisible" width="80%">-->
  182. <!-- <nic :device_type.sync="deviceType"></nic>-->
  183. <!-- </el-dialog>-->
  184. <el-dialog title="历史变更" :visible.sync="HistoryVisible" width="80%">
  185. <el-button type="primary" @click="addHistory" style="margin-bottom: 5px">添加历史变更</el-button>
  186. <el-timeline>
  187. <el-timeline-item v-for="item in history"
  188. :key="item.id"
  189. :timestamp="getDateTime(item.createDate)" placement="top">
  190. <el-card>
  191. <h4>{
  192. {item.message}}</h4>
  193. <p>XXX 提交于 {
  194. {getDateTime(item.createDate)}}</p>
  195. </el-card>
  196. </el-timeline-item>
  197. </el-timeline>
  198. </el-dialog>
  199. <el-dialog title="显示列编辑" :visible.sync="changeVisible" width="80%">
  200. <el-transfer v-model="colsList" :data="changeData" :titles="['所有列', '显示列']" :props="{key: 'value',label: 'desc'}"
  201. ></el-transfer>
  202. <div slot="footer" class="dialog-footer">
  203. <el-button type="primary" @click="saveCols()">提交</el-button>
  204. <el-button @click="changeVisible=false">取消</el-button>
  205. </div>
  206. </el-dialog>
  207. </div>
  208. </template>
  209. <script>
  210. import Sortable from 'sortablejs'
  211. import Pagination from '@/components/Pagination'
  212. import {fetchList, createDevice, modifyDevice, deleteDevice, addHistory, addHistories} from '@/api/device' // Secondary package based on el-pagination
  213. import {findAllDeviceType} from '@/api/devicetype'
  214. import {findAllCluster} from '@/api/cluster'
  215. import {saveColsInfo,saveOrders} from '@/api/userInfo'
  216. import cpu from '@/components/cpu'
  217. import Memory from "../../components/memory/index";
  218. import Disk from "../../components/disk/index";
  219. import Nic from "../../components/nic/index";
  220. import TagSelect from "../../components/TagSelect/index";
  221. import moment from "moment"
  222. import {mapGetters} from 'vuex'
  223. export default {
  224. name: 'Device',
  225. computed: {
  226. ...mapGetters([
  227. 'cols',
  228. 'orders'
  229. ])
  230. },
  231. components: {Disk, Memory, Pagination, cpu, Nic, TagSelect},
  232. data() {
  233. return {
  234. col: [],
  235. dropCol: [],
  236. rowClassName: "rowClass",
  237. cellClassName: "cellClass",
  238. deviceUrl: process.env.BASE_API + "/excel/device",
  239. collapse: ["1", "2", "3", "4"],
  240. CPUVisible: false,
  241. MemoryVisible: false,
  242. DiskVisible: false,
  243. NicVisible: false,
  244. HistoryVisible: false,
  245. changeVisible: false,
  246. colsList: [],
  247. history: [],
  248. history_deviceId: null,
  249. deviceType: null,
  250. temp: {
  251. id: null,
  252. name: null,
  253. clusterId: null,
  254. use: null,
  255. deliveryDate: null,
  256. type: null,
  257. manageIp: null,
  258. illoIp: null,
  259. period: null,
  260. remarks: null,
  261. deviceType: null,
  262. sn: null,
  263. tag: null,
  264. isDel: null,
  265. position: null,
  266. useUser: null,
  267. startDate: null,
  268. systemVersion: null,
  269. osVersion: null,
  270. outIp: null,
  271. publicIp: null,
  272. cn2Ip: null,
  273. computerPosition: null
  274. },
  275. list: null,
  276. total: 0,
  277. listLoading: true,
  278. listQuery: {
  279. page: 1,
  280. limit: 20,
  281. cluster: null,
  282. outIp: null
  283. },
  284. dialogFormVisible: false,
  285. editFlag: 0,
  286. rules: {
  287. // cn2Ip: [
  288. // {required: true, message: '请输入cn2ip', trigger: 'blur'}
  289. // ],
  290. },
  291. deviceTypeList: [],
  292. clusterList: [],
  293. changeData: [
  294. {value: "name", desc: "设备型号"},
  295. {value: "cluster.name", desc: "集群"},
  296. {value: "type", desc: "服务器分类"},
  297. {value: "sn", desc: "设备序列号"},
  298. {value: "manageIp", desc: "管理网"},
  299. {value: "illoIp", desc: "ILLO地址"},
  300. {value: "period", desc: "期数"},
  301. {value: "position", desc: "机架位置"},
  302. {value: "publicIp", desc: "公网"},
  303. {value: "cn2Ip", desc: "CN2"},
  304. {value: "outIp", desc: "存储外网"},
  305. {value: "systemVersion", desc: "系统版本"},
  306. {value: "osVersion", desc: "内核版本"},
  307. {value: "use", desc: "用途"},
  308. {value: "deliveryDate", desc: "交付日期"},
  309. {value: "useUser", desc: "申请人"},
  310. {value: "tag", desc: "项目名称"},
  311. {value: "remarks", desc: "备注"},
  312. {value: "computerPosition", desc: "机房位置"},
  313. ],
  314. multipleSelection: [],
  315. }
  316. },
  317. created() {
  318. this.getList()
  319. findAllDeviceType().then(response => {
  320. this.deviceTypeList = response.data;
  321. })
  322. findAllCluster().then(response => {
  323. this.clusterList = response.data;
  324. })
  325. },
  326. mounted() {
  327. this.columnDrop()
  328. this.col=this.getDropCol();
  329. this.dropCol=this.getDropCol();
  330. },
  331. methods: {
  332. getValue(row,type,prop){
  333. switch (type) {
  334. case 'cluster':
  335. return row.cluster.name
  336. case 'date':
  337. return this.getDate(row[prop])
  338. }
  339. },
  340. saveOrder(){
  341. let result = JSON.stringify(this.dropCol);
  342. let data = {
  343. orders: result,
  344. type: "device"
  345. }
  346. saveOrders(data).then(res => {
  347. this.$message({
  348. type: 'success',
  349. message: '保存成功 '
  350. });
  351. this.$store.dispatch('SetOrders', result)
  352. })
  353. },
  354. getDropCol(){
  355. if(this.orders&&this.orders.hasOwnProperty('device')){
  356. let data=JSON.parse(this.orders['device'])
  357. return data
  358. }
  359. return this.getCol()
  360. },
  361. getCol() {
  362. let allCols = [
  363. {prop: "select", label: "选择"},
  364. {prop: "index", label: "序号"},
  365. {prop: "name", label: "设备型号"},
  366. {prop: "cluster.name", label: "集群",type:"cluster"},
  367. {prop: "type", label: "服务器分类"},
  368. {prop: "sn", label: "设备序列号"},
  369. {prop: "manageIp", label: "管理网"},
  370. {prop: "illoIp", label: "ILLO地址"},
  371. {prop: "period", label: "期数"},
  372. {prop: "position", label: "机架位置"},
  373. {prop: "publicIp", label: "公网"},
  374. {prop: "cn2Ip", label: "CN2"},
  375. {prop: "outIp", label: "存储外网"},
  376. {prop: "systemVersion", label: "系统版本"},
  377. {prop: "osVersion", label: "内核版本"},
  378. {prop: "use", label: "用途"},
  379. {prop: "deliveryDate", label: "交付日期",type:"date"},
  380. {prop: "useUser", label: "申请人"},
  381. {prop: "tag", label: "项目名称"},
  382. {prop: "remarks", label: "备注"},
  383. {prop: "computerPosition", label: "机房位置"},
  384. ]
  385. if (this.cols && this.cols.hasOwnProperty('device')) {
  386. if (this.cols['device'] === "") {
  387. return allCols;
  388. }
  389. let str = this.cols['device'];
  390. let data = this.utils.str2Arr(str);
  391. let result=[]
  392. result.push({prop: "select", label: "选择"})
  393. result.push({prop: "index", label: "序号"})
  394. data.forEach(function (item) {
  395. allCols.forEach(function (col) {
  396. if (col.prop === item) {
  397. result.push(col);
  398. }
  399. })
  400. })
  401. return result;
  402. } else {
  403. return allCols;
  404. }
  405. },
  406. addHs() {
  407. this.$prompt('请输入变更记录', '提示', {
  408. confirmButtonText: '确定',
  409. cancelButtonText: '取消',
  410. }).then(({value}) => {
  411. addHistories({
  412. deviceId: this.multipleSelection,
  413. message: value
  414. }).then(response => {
  415. this.$message({
  416. type: 'success',
  417. message: '添加变更成功 '
  418. });
  419. this.HistoryVisible = false;
  420. this.getList();
  421. })
  422. }).catch(() => {
  423. this.$message({
  424. type: 'info',
  425. message: '取消添加'
  426. });
  427. });
  428. },
  429. handleSelectionChange(rows) {
  430. let data = [];
  431. rows.forEach(function (item) {
  432. data.push(item.id)
  433. })
  434. this.multipleSelection = data
  435. },
  436. changeCols() {
  437. if (this.cols && this.cols.hasOwnProperty('device')) {
  438. if (this.cols['device'] === "") {
  439. this.colsList = []
  440. this.changeVisible = true;
  441. return
  442. }
  443. let str = this.cols['device'];
  444. let data = this.utils.str2Arr(str);
  445. this.colsList = data;
  446. } else {
  447. this.colsList = [];
  448. }
  449. this.changeVisible = true;
  450. },
  451. saveCols() {
  452. let result = this.utils.arr2Str(this.colsList);
  453. let data = {
  454. cols: result,
  455. type: "device"
  456. }
  457. saveColsInfo(data).then(res => {
  458. this.changeVisible = false;
  459. this.$message({
  460. type: 'success',
  461. message: '变更成功 '
  462. });
  463. this.$store.dispatch('SetCols', result)
  464. location.reload()
  465. })
  466. },
  467. checkShow(name) {
  468. if (this.cols && this.cols !== '' && this.cols.hasOwnProperty('device')) {
  469. if (this.cols['device'] === "") {
  470. return true;
  471. }
  472. let checkList = this.utils.str2Arr(this.cols['device'])
  473. return checkList.indexOf(name) > -1;
  474. }
  475. return true;
  476. },
  477. getDate(time) {
  478. return moment(time).format('YYYY-MM-DD')
  479. },
  480. getDateTime(time) {
  481. return moment(time).format('YYYY-MM-DD HH:mm:ss')
  482. },
  483. addHistory() {
  484. this.$prompt('请输入变更记录', '提示', {
  485. confirmButtonText: '确定',
  486. cancelButtonText: '取消',
  487. }).then(({value}) => {
  488. addHistory({
  489. deviceId: this.history_deviceId,
  490. message: value
  491. }).then(response => {
  492. this.$message({
  493. type: 'success',
  494. message: '添加变更成功 '
  495. });
  496. this.HistoryVisible = false;
  497. this.getList();
  498. })
  499. }).catch(() => {
  500. this.$message({
  501. type: 'info',
  502. message: '取消添加'
  503. });
  504. });
  505. },
  506. historyInfo(row) {
  507. this.history = row.histories;
  508. this.HistoryVisible = true;
  509. this.history_deviceId = row.id
  510. },
  511. handleFilter() {
  512. this.listQuery.page = 1
  513. this.getList()
  514. },
  515. cpuInfo(row) {
  516. this.deviceType = row.deviceType
  517. this.CPUVisible = true;
  518. },
  519. memoryInfo(row) {
  520. this.deviceType = row.deviceType
  521. this.MemoryVisible = true;
  522. },
  523. nicInfo(row) {
  524. this.deviceType = row.deviceType
  525. this.NicVisible = true;
  526. },
  527. diskInfo(row) {
  528. this.deviceType = row.deviceType
  529. this.DiskVisible = true;
  530. },
  531. saveDevice(formName) {
  532. this.$refs[formName].validate((valid) => {
  533. if (valid) {
  534. if (this.editFlag === 0) {
  535. createDevice(
  536. this.temp
  537. ).then(response => {
  538. this.$message({
  539. message: '保存成功',
  540. type: 'success'
  541. });
  542. this.getList();
  543. this.resetDeviceForm('ruleForm')
  544. })
  545. } else {
  546. modifyDevice(
  547. this.temp
  548. ).then(response => {
  549. this.$message({
  550. message: '保存成功',
  551. type: 'success'
  552. });
  553. this.getList();
  554. this.resetDeviceForm('ruleForm')
  555. })
  556. }
  557. } else {
  558. this.$message.error('保存失败,请重试');
  559. return false;
  560. }
  561. });
  562. },
  563. handleAvatarSuccess(res, file) {
  564. if (res.code != 200) {
  565. this.$message({
  566. message: res.msg,
  567. type: 'error'
  568. });
  569. return
  570. }
  571. this.$message({
  572. message: '上传成功',
  573. type: 'success'
  574. });
  575. this.getList()
  576. },
  577. resetDeviceForm(formName) {
  578. this.$refs[formName].resetFields();
  579. this.dialogFormVisible = false;
  580. },
  581. getList() {
  582. this.listLoading = true
  583. fetchList(this.listQuery).then(response => {
  584. this.list = response.data.content;
  585. this.total = response.data.totalElements;
  586. this.listLoading = false
  587. })
  588. },
  589. createDevice() {
  590. this.resetTemp()
  591. this.dialogFormVisible = true;
  592. this.editFlag = 0;
  593. },
  594. editDevice(item) {
  595. this.resetTemp()
  596. this.temp.id = item.id;
  597. this.temp.clusterId = item.cluster.id;
  598. this.temp.name = item.name;
  599. this.temp.use = item.use;
  600. this.temp.deliveryDate = item.deliveryDate;
  601. this.temp.type = item.type;
  602. this.temp.period = item.period;
  603. this.temp.manageIp = item.manageIp;
  604. this.temp.illoIp = item.illoIp;
  605. this.temp.remarks = item.remarks;
  606. this.temp.deviceType = item.deviceType;
  607. this.temp.sn = item.sn;
  608. this.temp.tag = item.tag;
  609. this.temp.position = item.position;
  610. this.temp.systemVersion = item.systemVersion;
  611. this.temp.osVersion = item.osVersion;
  612. this.temp.publicIp = item.publicIp;
  613. this.temp.outIp = item.outIp;
  614. this.temp.cn2Ip = item.cn2Ip;
  615. this.temp.computerPosition = item.computerPosition
  616. this.dialogFormVisible = true;
  617. this.editFlag = 1;
  618. },
  619. resetTemp() {
  620. this.temp = {
  621. id: null,
  622. name: null,
  623. clusterId: null,
  624. use: null,
  625. deliveryDate: null,
  626. type: null,
  627. manageIp: null,
  628. illoIp: null,
  629. period: null,
  630. remarks: null,
  631. deviceType: null,
  632. sn: null,
  633. tag: null,
  634. isDel: null,
  635. position: null,
  636. useUser: null,
  637. startDate: null,
  638. systemVersion: null,
  639. osVersion: null,
  640. outIp: null,
  641. publicIp: null,
  642. cn2Ip: null,
  643. }
  644. },
  645. deleteDevice(row) {
  646. this.$confirm('此操作将删除该资产, 是否继续?', '提示', {
  647. confirmButtonText: '确定',
  648. cancelButtonText: '取消',
  649. type: 'warning'
  650. }).then(() => {
  651. deleteDevice(row.id).then(response => {
  652. this.getList();
  653. this.$message({
  654. type: 'success',
  655. message: '删除成功!'
  656. });
  657. })
  658. }).catch(() => {
  659. this.$message({
  660. type: 'info',
  661. message: '已取消删除'
  662. });
  663. });
  664. },
  665. //列拖拽
  666. columnDrop() {
  667. const wrapperTr = document.querySelector('.el-table__header-wrapper tr')
  668. this.sortable = Sortable.create(wrapperTr, {
  669. animation: 180,
  670. delay: 0,
  671. onEnd: evt => {
  672. const oldItem = this.dropCol[evt.oldIndex]
  673. this.dropCol.splice(evt.oldIndex, 1)
  674. this.dropCol.splice(evt.newIndex, 0, oldItem)
  675. }
  676. })
  677. }
  678. }
  679. }
  680. </script>
  681. <style>
  682. .el-dropdown-link {
  683. cursor: pointer;
  684. color: #409EFF;
  685. }
  686. .demo-table-expand {
  687. font-size: 0;
  688. }
  689. .demo-table-expand label {
  690. width: 90px;
  691. color: #99a9bf;
  692. }
  693. .demo-table-expand .el-form-item {
  694. margin-right: 0;
  695. margin-bottom: 0;
  696. width: 50%;
  697. }
  698. .rowClass {
  699. height: 30px;
  700. padding: 0 !important;
  701. }
  702. .cellClass {
  703. padding: 2px !important;
  704. }
  705. </style>

发表评论

表情:
评论列表 (有 0 条评论,454人围观)

还没有评论,来说两句吧...

相关阅读

    相关 表格宽度

    问题 普通表格的列是不能够通过用户操作改变宽度, 即动态改变列的宽度。 有时候, 有的列内容是多的,不够显示, 有的列内容是少的,不用太多宽度显示, 但是内容是动态的,