import * as api from '@/api';
|
import * as tools from '@/utils/tools.js';
|
|
const usePagePermission = (
|
pageId,
|
mounted = () => {
|
}
|
) => {
|
const buttons = [];
|
const tabs = [];
|
let page = {};
|
|
onMounted(async () => {
|
const {data} = await api.page.getPage({pageId});
|
page = data.page;
|
page.tabs.forEach(e => {
|
tabs.push({name: e.code, label: tools.decode(e.name)});
|
});
|
const code = page.tabs[0].code;
|
subActive(code);
|
mounted({buttons, tabs});
|
});
|
|
const subActive = (val) => {
|
const tabId = page.tabs.find(e => e.code === val).id;
|
buttons.splice(0, buttons.length);
|
page.buttons
|
.filter(e => e.tab_id === tabId)
|
.forEach(e => {
|
buttons.push({
|
name: e.code,
|
label: tools.decode(e.title)
|
});
|
})
|
}
|
|
return [buttons, tabs, subActive];
|
};
|
|
const useDesignerOptions = (props) => {
|
const globalOptions = {};
|
|
const optionsHandler = ({options, children}) => {
|
globalOptions[options.ref] = options;
|
(children || []).forEach(child => optionsHandler(child));
|
}
|
|
optionsHandler(props);
|
|
return [globalOptions]
|
}
|
|
export default {
|
usePagePermission,
|
useDesignerOptions,
|
};
|