Browse Source

菜单管理tree处理

daxiongYang 7 years ago
parent
commit
7ee6393e9b
4 changed files with 58 additions and 85 deletions
  1. 2 2
      .babelrc
  2. 3 0
      package.json
  3. 2 2
      src/element-ui/index.js
  4. 51 81
      src/views/menu/index.vue

+ 2 - 2
.babelrc

5
    }],
5
    }],
6
    "stage-2"
6
    "stage-2"
7
  ],
7
  ],
8
  "plugins": ["transform-runtime", ["component", [
8
  "plugins": ["transform-runtime", "transform-vue-jsx", ["component", [
9
    {
9
    {
10
      "libraryName": "element-ui",
10
      "libraryName": "element-ui",
11
      "styleLibraryName": "theme-chalk"
11
      "styleLibraryName": "theme-chalk"
14
  "env": {
14
  "env": {
15
    "test": {
15
    "test": {
16
      "presets": ["env", "stage-2"],
16
      "presets": ["env", "stage-2"],
17
      "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"]
17
      "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node", "transform-vue-jsx", "istanbul"]
18
    }
18
    }
19
  }
19
  }
20
}
20
}

+ 3 - 0
package.json

15
  },
15
  },
16
  "dependencies": {
16
  "dependencies": {
17
    "axios": "0.17.1",
17
    "axios": "0.17.1",
18
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
18
    "babel-plugin-component": "0.10.1",
19
    "babel-plugin-component": "0.10.1",
20
    "babel-plugin-syntax-jsx": "^6.18.0",
21
    "babel-plugin-transform-vue-jsx": "^3.5.1",
19
    "babel-polyfill": "6.26.0",
22
    "babel-polyfill": "6.26.0",
20
    "element-ui": "2.0.7",
23
    "element-ui": "2.0.7",
21
    "vue": "2.5.2",
24
    "vue": "2.5.2",

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

38
  // DatePicker,
38
  // DatePicker,
39
  // TimeSelect,
39
  // TimeSelect,
40
  // TimePicker,
40
  // TimePicker,
41
  // Popover,
41
  Popover,
42
  Tooltip,
42
  Tooltip,
43
  Breadcrumb,
43
  Breadcrumb,
44
  BreadcrumbItem,
44
  BreadcrumbItem,
107
// Vue.use(DatePicker)
107
// Vue.use(DatePicker)
108
// Vue.use(TimeSelect)
108
// Vue.use(TimeSelect)
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)
112
Vue.use(Breadcrumb)
113
Vue.use(BreadcrumbItem)
113
Vue.use(BreadcrumbItem)

+ 51 - 81
src/views/menu/index.vue

5
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
5
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
6
      </el-form-item>
6
      </el-form-item>
7
    </el-form>
7
    </el-form>
8
    <tree-table
9
      :columns="treeTableColumns"
8
    <el-tree
10
      :data="dataList"
9
      :data="dataList"
11
      highlight-current-row
12
      border
13
      style="width: 100%;">
14
      <el-table-column
15
        prop="name"
16
        header-align="center"
17
        align="center"
18
        label="菜单名称">
19
      </el-table-column>
20
      <el-table-column
21
        prop="parentName"
22
        header-align="center"
23
        align="center"
24
        label="上级菜单">
25
      </el-table-column>
26
      <el-table-column
27
        prop="icon"
28
        header-align="center"
29
        align="center"
30
        label="图标">
31
      </el-table-column>
32
      <el-table-column
33
        prop="type"
34
        header-align="center"
35
        align="center"
36
        label="类型">
37
      </el-table-column>
38
      <el-table-column
39
        prop="orderNum"
40
        header-align="center"
41
        align="center"
42
        label="排序号">
43
      </el-table-column>
44
      <el-table-column
45
        prop="url"
46
        header-align="center"
47
        align="center"
48
        label="菜单URL">
49
      </el-table-column>
50
      <el-table-column
51
        prop="perms"
52
        header-align="center"
53
        align="center"
54
        label="授权标识">
55
      </el-table-column>
56
      <el-table-column
57
        fixed="right"
58
        header-align="center"
59
        align="center"
60
        width="200"
61
        label="操作">
62
        <template slot-scope="scope">
63
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
64
          <el-button type="text" size="small" @click="deleteHandle(scope.row.userId)">删除</el-button>
65
        </template>
66
      </el-table-column>
67
    </tree-table>
10
      :props="dataListTreeProps"
11
      :highlight-current="true"
12
      node-key="menuId"
13
      :default-expand-all="true"
14
      :expand-on-click-node="false"
15
      @mouseleave.native="dataListTreeActiveNodeId = 0"
16
      :render-content="dataListTreeRenderContent">
17
    </el-tree>
68
    <!-- 弹窗, 新增 / 修改 -->
18
    <!-- 弹窗, 新增 / 修改 -->
69
    <el-dialog
19
    <el-dialog
70
      :title="!addOrUpdateForm.userId ? '新增' : '修改'"
20
      :title="!addOrUpdateForm.userId ? '新增' : '修改'"
88
        </el-form-item>
38
        </el-form-item>
89
        <el-form-item label="角色" size="mini" prop="roleIdList">
39
        <el-form-item label="角色" size="mini" prop="roleIdList">
90
          <el-checkbox-group v-model="addOrUpdateForm.roleIdList">
40
          <el-checkbox-group v-model="addOrUpdateForm.roleIdList">
91
            <el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{ role.roleName }}</el-checkbox>
41
            <!-- <el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{ role.roleName }}</el-checkbox> -->
92
          </el-checkbox-group>
42
          </el-checkbox-group>
93
        </el-form-item>
43
        </el-form-item>
94
        <el-form-item label="状态" size="mini" prop="status">
44
        <el-form-item label="状态" size="mini" prop="status">
107
</template>
57
</template>
108
58
109
<script>
59
<script>
110
  import TreeTable from '@/components/tree-table'
111
  import API from '@/api'
60
  import API from '@/api'
112
  import { treeDataTranslate } from '@/utils'
61
  import { treeDataTranslate } from '@/utils'
113
  import { isEmail, isMobile } from '@/utils/validate'
62
  import { isEmail, isMobile } from '@/utils/validate'
144
        }
93
        }
145
      }
94
      }
146
      return {
95
      return {
147
        dataForm: {
148
          userName: ''
96
        dataForm: {},
97
        dataListTreeProps: {
98
          label: 'name',
99
          children: 'children'
149
        },
100
        },
150
        treeTableColumns: [
151
          {
152
            text: 'ID',
153
            value: 'menuId'
154
          }
155
        ],
101
        dataListTreeHandlebarVisible: false,
102
        dataListTreeActiveNodeId: 0,
156
        dataList: [],
103
        dataList: [],
157
        pageIndex: 1,
158
        pageSize: 10,
159
        totalPage: 0,
160
        dataListLoading: false,
161
        dataListSelections: [],
162
        roleList: [],
163
        addOrUpdateDialogVisible: false,
104
        addOrUpdateDialogVisible: false,
164
        addOrUpdateForm: {
105
        addOrUpdateForm: {
165
          userId: 0,
106
          userId: 0,
192
        }
133
        }
193
      }
134
      }
194
    },
135
    },
195
    components: {
196
      TreeTable
197
    },
198
    activated () {
136
    activated () {
199
      this.getDataList()
137
      this.getDataList()
200
    },
138
    },
207
          this.dataListLoading = false
145
          this.dataListLoading = false
208
        })
146
        })
209
      },
147
      },
210
      // 多选
211
      selectionChangeHandle (val) {
212
        this.dataListSelections = val
148
      // 树形数据列表, 呈现内容
149
      dataListTreeRenderContent (h, { node, data, store }) {
150
        return (
151
          <div on-mouseenter={ () => this.dataListTreeMouseenterHandle(node) } class="tree-handlebar">
152
            <span>{ data.menuId + '. ' + node.label }</span>
153
            {
154
              this.dataListTreeActiveNodeId === node.id
155
              ? <span class="tree-handlebar__btns">
156
                <el-button type="text" on-click={ () => this.append(data) }>修改</el-button>
157
                <el-button type="text" on-click={ () => this.remove(node, data) }>删除</el-button>
158
              </span>
159
              : ''
160
            }
161
          </div>
162
        )
163
      },
164
      // 树形数据列表, 数据进入处理
165
      dataListTreeMouseenterHandle (node) {
166
        this.dataListTreeActiveNodeId = node.id
213
      },
167
      },
214
      // 新增 / 修改
168
      // 新增 / 修改
215
      addOrUpdateHandle (id) {
169
      addOrUpdateHandle (id) {
296
    }
250
    }
297
  }
251
  }
298
</script>
252
</script>
253
254
<style lang="scss">
255
  .mod-menu {
256
    .tree-handlebar {
257
      width: 100%;
258
    }
259
    .tree-handlebar__btns {
260
      margin-left: 15px;
261
      > .el-button {
262
        padding: 0;
263
        font-size: 12px;
264
      }
265
    }
266
  }
267
</style>
268