|
|
@@ -13,16 +13,55 @@
|
|
|
plain
|
|
|
@click="handleDelete">删 除
|
|
|
</el-button>
|
|
|
+ <el-button size="small"
|
|
|
+ icon="iconfont iconicon_subordinate"
|
|
|
+ @click="handleMenu(done)">
|
|
|
+ 选择租户默认角色菜单参数
|
|
|
+ </el-button>
|
|
|
</template>
|
|
|
</avue-crud>
|
|
|
+ <el-dialog title="租户默认角色菜单配置"
|
|
|
+ append-to-body
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :visible.sync="box"
|
|
|
+ width="450px">
|
|
|
+ <el-tree :data="menuGrantList"
|
|
|
+ show-checkbox
|
|
|
+ node-key="id"
|
|
|
+ ref="treeMenu"
|
|
|
+ :props="props">
|
|
|
+ </el-tree>
|
|
|
+ <el-input
|
|
|
+ type="textarea"
|
|
|
+ :autosize="{ minRows: 2, maxRows: 5}"
|
|
|
+ ref="generateMenuJson"
|
|
|
+ disabled
|
|
|
+ placeholder="生成的JSON文本"
|
|
|
+ v-model="jsonText">
|
|
|
+ </el-input>
|
|
|
+ <span slot="footer" class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="generateMenuJson" :loading="btnLoading">生成JSON</el-button>
|
|
|
+ </span>
|
|
|
+ </el-dialog>
|
|
|
</basic-container>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import {grantTree} from "@/api/system/role";
|
|
|
+import {getMenuListByIds, detail} from "@/api/system/param";
|
|
|
|
|
|
export default window.$crudCommon({
|
|
|
data() {
|
|
|
- return {}
|
|
|
+ return {
|
|
|
+ box: false,
|
|
|
+ btnLoading: false,
|
|
|
+ menuGrantList: [],
|
|
|
+ jsonText: "",
|
|
|
+ props: {
|
|
|
+ label: "title",
|
|
|
+ value: "key"
|
|
|
+ },
|
|
|
+ }
|
|
|
},
|
|
|
computed: {
|
|
|
permissionList() {
|
|
|
@@ -34,7 +73,109 @@ export default window.$crudCommon({
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
- methods: {}
|
|
|
+ methods: {
|
|
|
+ handleMenu() {
|
|
|
+ this.box = true;
|
|
|
+ this.jsonText = "";
|
|
|
+ this.menuTreeObj = [];
|
|
|
+ grantTree().then(res => {
|
|
|
+ this.menuGrantList = res.data.data.menu;
|
|
|
+ this.getCheckMenuValue();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生成菜单JSON文本
|
|
|
+ */
|
|
|
+ generateMenuJson() {
|
|
|
+ const checkedKeys = this.$refs.treeMenu.getCheckedKeys(false);
|
|
|
+ const hafCheckedKeys = this.$refs.treeMenu.getHalfCheckedKeys(false);
|
|
|
+ const menuKeys = checkedKeys.concat(hafCheckedKeys)
|
|
|
+ if (checkedKeys.length > 0) {
|
|
|
+ this.btnLoading = true;
|
|
|
+ getMenuListByIds(menuKeys.join(",")).then(res => {
|
|
|
+ let menuJSON = [];
|
|
|
+ res.data.data.forEach(ele => {
|
|
|
+ menuJSON.push(this.getChildMenu(ele));
|
|
|
+ });
|
|
|
+ this.jsonText = JSON.stringify(menuJSON);
|
|
|
+ this.copy(JSON.stringify(menuJSON));
|
|
|
+ this.$message.success("生成菜单JSON文本成功,并复制到剪切板");
|
|
|
+ this.btnLoading = false;
|
|
|
+ }).catch(e => {
|
|
|
+ this.btnLoading = false;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$message.warning("最少选择一项");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 遍历子菜单对象
|
|
|
+ * @param menu
|
|
|
+ * @returns {{code, childMenu: null}}
|
|
|
+ */
|
|
|
+ getChildMenu(menu) {
|
|
|
+ const menuObj = {
|
|
|
+ key: menu.id,
|
|
|
+ code: menu.code,
|
|
|
+ childMenu: null,
|
|
|
+ };
|
|
|
+ if (menu.children) {
|
|
|
+ menuObj.childMenu = [];
|
|
|
+ for (const childMenu of menu.children) {
|
|
|
+ menuObj.childMenu.push(this.getChildMenu(childMenu));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return menuObj;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 获取菜单选择值
|
|
|
+ */
|
|
|
+ getCheckMenuValue() {
|
|
|
+ detail({
|
|
|
+ paramKey: "tenant.default.menuJSON"
|
|
|
+ }).then(res => {
|
|
|
+ if (res.data.data) {
|
|
|
+ const menuJSON = JSON.parse(res.data.data.paramValue);
|
|
|
+ this.getChildMenuKeys(menuJSON, this.menuTreeObj);
|
|
|
+ this.$refs.treeMenu.setCheckedKeys(this.menuTreeObj);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 获取子菜单key
|
|
|
+ * @param menuList
|
|
|
+ * @param keys
|
|
|
+ */
|
|
|
+ getChildMenuKeys(menuList, keys) {
|
|
|
+ for (const menu of menuList) {
|
|
|
+ if (menu.childMenu && menu.length !== 0) {
|
|
|
+ this.getChildMenuKeys(menu.childMenu, keys);
|
|
|
+ } else {
|
|
|
+ keys.push(menu.key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 复制功能
|
|
|
+ copy(data) {
|
|
|
+ // 存储传递过来的数据
|
|
|
+ let OrderNumber = data;
|
|
|
+ // 创建一个input 元素
|
|
|
+ // createElement() 方法通过指定名称创建一个元素
|
|
|
+ let newInput = document.createElement("input");
|
|
|
+ // 讲存储的数据赋值给input的value值
|
|
|
+ newInput.value = OrderNumber;
|
|
|
+ // appendChild() 方法向节点添加最后一个子节点。
|
|
|
+ document.body.appendChild(newInput);
|
|
|
+ // 选中input元素中的文本
|
|
|
+ // select() 方法用于选择该元素中的文本。
|
|
|
+ newInput.select();
|
|
|
+ // 执行浏览器复制命令
|
|
|
+ // execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令
|
|
|
+ document.execCommand("Copy");
|
|
|
+ // 清空输入框
|
|
|
+ newInput.remove();
|
|
|
+ },
|
|
|
+ }
|
|
|
}, {
|
|
|
//模块路径
|
|
|
name: 'system/param',
|