Browse Source

优化table-tree-column

daxiong.yang 7 years ago
parent
commit
ceb64d1fc1

+ 1 - 1
README.md

7
7
8
## renren-fast-vue
8
## renren-fast-vue
9
- renren-fast-vue基于vue、element-ui构建开发,实现renren-fast后台管理前端功能,提供一套更优的前端解决方案
9
- renren-fast-vue基于vue、element-ui构建开发,实现renren-fast后台管理前端功能,提供一套更优的前端解决方案
10
- 演示地址:[fast.demo.renren.io](//fast.demo.renren.io)
10
- 演示地址:[fast.demo.renren.io](http://fast.demo.renren.io)
11
11
12
![demo-screenshot](https://github.com/daxiongYang/renren-fast-vue/blob/master/demo-screenshot/1.png)
12
![demo-screenshot](https://github.com/daxiongYang/renren-fast-vue/blob/master/demo-screenshot/1.png)
13
13

+ 38 - 83
src/components/table-tree-column/index.vue

1
<template>
1
<template>
2
  <el-table-column :prop="prop" v-bind="$attrs">
2
  <el-table-column :prop="prop" v-bind="$attrs">
3
    <template slot-scope="scope">
3
    <template slot-scope="scope">
4
      <span v-if="hasChild(scope.row)" @click.prevent="expandedHandle(scope.$index, scope.row)">
5
        <span :style="{ 'padding-left': paddingLeft(scope.row) }">
6
          <i :class="icon(scope.row)"></i>
7
          <i :class="floderIcon(scope.row)" style="padding-right: 7px;"></i>
8
        </span>
9
        <span>{{scope.row[prop]}}</span>
10
      </span>
11
      <span v-if="!hasChild(scope.row)">
12
        <span :style="{ 'padding-left': paddingLeft(scope.row) }">
13
          <i :class="fileIcon" style="padding-right: 7px; padding-left:18px;"></i>
14
        </span>
15
        <span>{{scope.row[prop]}}</span>
4
      <span @click.prevent="toggleHandle(scope.$index, scope.row)" :style="childStyles(scope.row)">
5
        <i :class="iconClasses(scope.row)" :style="iconStyles(scope.row)"></i>
6
        {{ scope.row[prop] }}
16
      </span>
7
      </span>
17
    </template>
8
    </template>
18
  </el-table-column>
9
  </el-table-column>
19
</template>
10
</template>
20
11
21
<script>
12
<script>
13
  import isArray from 'lodash/isArray'
22
  export default {
14
  export default {
23
    name: 'table-tree-column',
15
    name: 'table-tree-column',
24
    data () {
25
      return { loading: false }
26
    },
27
    props: {
16
    props: {
28
      prop: {
17
      prop: {
29
        type: String
18
        type: String
32
        type: String,
21
        type: String,
33
        default: 'id'
22
        default: 'id'
34
      },
23
      },
35
      childNumKey: {
36
        type: String,
37
        default: 'child_num'
38
      },
39
      parentKey: {
24
      parentKey: {
40
        type: String,
25
        type: String,
41
        default: 'parentId'
26
        default: 'parentId'
42
      },
27
      },
43
      levelKey: {
28
      levelKey: {
44
        type: String,
29
        type: String,
45
        default: 'depth'
30
        default: '_level'
46
      },
31
      },
47
      childKey: {
32
      childKey: {
48
        type: String,
33
        type: String,
49
        default: 'children'
34
        default: 'children'
50
      },
51
      fileIcon: {
52
        type: String,
53
        default: 'el-icon-file'
54
      },
55
      folderIcon: {
56
        type: String,
57
        default: 'el-icon-folder'
58
      }
35
      }
59
    },
36
    },
60
    created () {
61
      console.log(this.$attrs)
62
    },
63
    methods: {
37
    methods: {
64
      floderIcon (row) {
65
        return row._expanded ? this.folderIcon + '-open' : this.folderIcon
38
      childStyles (row) {
39
        return { 'padding-left': (row[this.levelKey] > 1 ? row[this.levelKey] * 7 : 0) + 'px'  return { 'padding-left': (row[this.levelKey] > 1 ? row[this.levelKey] * 7 : 0) + 'px' }
66
      },
40
      },
67
      hasChild (row) {
68
        if (row[this.childNumKey] !== undefined) {
69
          return row[this.childNumKey] > 0 || false
70
        } else if (row[this.childKey] !== undefined) {
71
          return row[this.childKey].length > 0 || false
72
        } else {
73
          return false
74
        }
41
      iconClasses (row) {
42
        return [ !row._expanded ? 'el-icon-caret-right' : 'el-icon-caret-bottom' ]
75
      },
43
      },
76
      paddingLeft (row) {
77
        return (parseInt(row[this.levelKey]) * 14) + 'px'
44
      iconStyles (row) {
45
        return { 'visibility': this.hasChild(row) ? 'visible' : 'hidden' }
78
      },
46
      },
79
      icon (row) {
80
        return row._expanded ? 'el-icon-caret-bottom' : 'el-icon-caret-right'
47
      hasChild (row) {
48
        return (isArray(row[this.childKey]) && row[this.childKey].length >= 1) || false
81
      },
49
      },
82
      expandedHandle (index, row) {
83
        var data = JSON.parse(JSON.stringify(this.$parent.store.states.data))
84
        data[index]._expanded = !data[index]._expanded
85
        console.log(data)
86
        if (data[index]._expanded) {
87
          data = data.splice(0, index + 1).concat(row[this.childKey]).concat(data)
50
      // 切换处理
51
      toggleHandle (index, row) {
52
        if (this.hasChild(row)) {
53
          var data = JSON.parse(JSON.stringify(this.$parent.store.states.data))
54
          data[index]._expanded = !data[index]._expanded
55
          if (data[index]._expanded) {
56
            data = data.splice(0, index + 1).concat(row[this.childKey]).concat(data)
57
          } else {
58
            data = this.removeChildNode(data, row[this.treeKey])
59
          }
88
          this.$parent.store.commit('setData', data)
60
          this.$parent.store.commit('setData', data)
89
        } else {
90
          var id = row[this.treeKey]
91
          var result = []
92
          var removeIds = this.descendantsIds(id, data, this.parentKey, this.treeKey)
93
          data.forEach(item => {
94
            if (removeIds.indexOf(item[this.treeKey]) === -1) {
95
              result.push(item)
96
            }
61
          this.$nextTick(() => {
62
            this.$parent.doLayout()
97
          })
63
          })
98
          data = result
99
          this.$parent.store.commit('setData', data)
100
        }
64
        }
101
      },
65
      },
102
      descendantsIds (id, data, parentKey, treeKey) {
103
        var result = []
104
        var compare = [id]
105
        var length = -1
106
        // if (compare.length !== -1) {
107
        //   data.forEach(item => {
108
        //     if (compare.indexOf(item[parentKey]) > -1 && compare.indexOf(item[treeKey]) === -1) {
109
        //       result.push(item[treeKey])
110
        //       compare.push(item[treeKey])
111
        //     }
112
        //   })
113
        // }
114
        while (length !== compare.length) {
115
          length = compare.length
116
          console.log(length)
117
          data.forEach(item => {
118
            if (compare.indexOf(item[parentKey]) > -1 && compare.indexOf(item[treeKey]) === -1) {
119
              result.push(item[treeKey])
120
              compare.push(item[treeKey])
121
            }
122
          })
66
      // 移除子节点
67
      removeChildNode (data, parentId) {
68
        var parentIds = isArray(parentId) ? parentId : [parentId]
69
        if (parentId.length <= 0) {
70
          return data
71
        }
72
        var ids = []
73
        for (var i = 0; i < data.length; i++) {
74
          if (parentIds.indexOf(data[i][this.parentKey]) !== -1 && parentIds.indexOf(data[i][this.treeKey]) === -1) {
75
            ids.push(data.splice(i, 1)[0][this.treeKey])
76
            i--
77
          }
123
        }
78
        }
124
        return result
79
        return this.removeChildNode(data, ids)
125
      }
80
      }
126
    }
81
    }
127
  }
82
  }

+ 4 - 4
src/element-ui/index.js

40
  // TimePicker,
40
  // TimePicker,
41
  Popover,
41
  Popover,
42
  Tooltip,
42
  Tooltip,
43
  Breadcrumb,
44
  BreadcrumbItem,
43
  // Breadcrumb,
44
  // BreadcrumbItem,
45
  Form,
45
  Form,
46
  FormItem,
46
  FormItem,
47
  Tabs,
47
  Tabs,
109
// Vue.use(TimePicker)
109
// Vue.use(TimePicker)
110
Vue.use(Popover)
110
Vue.use(Popover)
111
Vue.use(Tooltip)
111
Vue.use(Tooltip)
112
Vue.use(Breadcrumb)
113
Vue.use(BreadcrumbItem)
112
// Vue.use(Breadcrumb)
113
// Vue.use(BreadcrumbItem)
114
Vue.use(Form)
114
Vue.use(Form)
115
Vue.use(FormItem)
115
Vue.use(FormItem)
116
Vue.use(Tabs)
116
Vue.use(Tabs)

+ 4 - 0
src/utils/index.js

32
      if (!temp[data[k][pid]]['children']) {
32
      if (!temp[data[k][pid]]['children']) {
33
        temp[data[k][pid]]['children'] = []
33
        temp[data[k][pid]]['children'] = []
34
      }
34
      }
35
      if (!temp[data[k][pid]]['_level']) {
36
        temp[data[k][pid]]['_level'] = 1
37
      }
38
      data[k]['_level'] = temp[data[k][pid]]._level + 1
35
      temp[data[k][pid]]['children'].push(data[k])
39
      temp[data[k][pid]]['children'].push(data[k])
36
    } else {
40
    } else {
37
      res.push(data[k])
41
      res.push(data[k])

+ 1 - 1
src/views/config/index.vue

51
        fixed="right"
51
        fixed="right"
52
        header-align="center"
52
        header-align="center"
53
        align="center"
53
        align="center"
54
        width="200"
54
        width="150"
55
        label="操作">
55
        label="操作">
56
        <template slot-scope="scope">
56
        <template slot-scope="scope">
57
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
57
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>

+ 5 - 0
src/views/log/index.vue

36
        prop="method"
36
        prop="method"
37
        header-align="center"
37
        header-align="center"
38
        align="center"
38
        align="center"
39
        width="150"
40
        :show-overflow-tooltip="true"
39
        label="请求方法">
41
        label="请求方法">
40
      </el-table-column>
42
      </el-table-column>
41
      <el-table-column
43
      <el-table-column
42
        prop="params"
44
        prop="params"
43
        header-align="center"
45
        header-align="center"
44
        align="center"
46
        align="center"
47
        width="150"
48
        :show-overflow-tooltip="true"
45
        label="请求参数">
49
        label="请求参数">
46
      </el-table-column>
50
      </el-table-column>
47
      <el-table-column
51
      <el-table-column
54
        prop="ip"
58
        prop="ip"
55
        header-align="center"
59
        header-align="center"
56
        align="center"
60
        align="center"
61
        width="150"
57
        label="IP地址">
62
        label="IP地址">
58
      </el-table-column>
63
      </el-table-column>
59
      <el-table-column
64
      <el-table-column

+ 4 - 4
src/views/menu/index.vue

19
      <table-tree-column
19
      <table-tree-column
20
        prop="name"
20
        prop="name"
21
        header-align="center"
21
        header-align="center"
22
        align="center"
23
        treeKey="menuId"
22
        treeKey="menuId"
24
        min-width="120"
23
        width="150"
25
        label="名称">
24
        label="名称">
26
      </table-tree-column>
25
      </table-tree-column>
27
      <el-table-column
26
      <el-table-column
28
        prop="parentName"
27
        prop="parentName"
29
        header-align="center"
28
        header-align="center"
30
        align="center"
29
        align="center"
31
        min-width="120"
30
        width="120"
32
        label="上级菜单">
31
        label="上级菜单">
33
      </el-table-column>
32
      </el-table-column>
34
      <el-table-column
33
      <el-table-column
77
        fixed="right"
76
        fixed="right"
78
        header-align="center"
77
        header-align="center"
79
        align="center"
78
        align="center"
80
        width="200"
79
        width="150"
81
        label="操作">
80
        label="操作">
82
        <template slot-scope="scope">
81
        <template slot-scope="scope">
83
          <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.menuId)">修改</el-button>
82
          <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.menuId)">修改</el-button>
117
        this.dataListLoading = true
116
        this.dataListLoading = true
118
        API.menu.list().then(({data}) => {
117
        API.menu.list().then(({data}) => {
119
          this.dataList = treeDataTranslate(data, 'menuId')
118
          this.dataList = treeDataTranslate(data, 'menuId')
119
          console.log(this.dataList)
120
          this.dataListLoading = false
120
          this.dataListLoading = false
121
        })
121
        })
122
      },
122
      },

+ 1 - 1
src/views/oss/index.vue

43
        fixed="right"
43
        fixed="right"
44
        header-align="center"
44
        header-align="center"
45
        align="center"
45
        align="center"
46
        width="200"
46
        width="150"
47
        label="操作">
47
        label="操作">
48
        <template slot-scope="scope">
48
        <template slot-scope="scope">
49
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
49
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>

+ 1 - 1
src/views/role/index.vue

52
        fixed="right"
52
        fixed="right"
53
        header-align="center"
53
        header-align="center"
54
        align="center"
54
        align="center"
55
        width="200"
55
        width="150"
56
        label="操作">
56
        label="操作">
57
        <template slot-scope="scope">
57
        <template slot-scope="scope">
58
          <el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>
58
          <el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>

+ 1 - 1
src/views/schedule/index.vue

77
        fixed="right"
77
        fixed="right"
78
        header-align="center"
78
        header-align="center"
79
        align="center"
79
        align="center"
80
        width="200"
80
        width="150"
81
        label="操作">
81
        label="操作">
82
        <template slot-scope="scope">
82
        <template slot-scope="scope">
83
          <el-button v-if="isAuth('sys:schedule:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.jobId)">修改</el-button>
83
          <el-button v-if="isAuth('sys:schedule:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.jobId)">修改</el-button>

+ 1 - 1
src/views/user/index.vue

68
        fixed="right"
68
        fixed="right"
69
        header-align="center"
69
        header-align="center"
70
        align="center"
70
        align="center"
71
        width="200"
71
        width="150"
72
        label="操作">
72
        label="操作">
73
        <template slot-scope="scope">
73
        <template slot-scope="scope">
74
          <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
74
          <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>