Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cust_anno_permission #100

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
- name: feAnnotation
description: 前端权限注解
applyTo: ViewElement
belong: annotation
labels: [Runtime]
properties:
- name: useAnno
title: 开启前端权限注解
defaultValue:
concept: DefaultValue
expression:
concept: BooleanLiteral
value: true
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeName: Boolean
typeNamespace: nasl.core
setter:
concept: SwitchSetter
# - name: feInput
# title: 需要传入的值
# defaultValue:
# concept: DefaultValue
# expression:
# concept: StringLiteral
# value: '默认值22'
# typeAnnotation:
# concept: TypeAnnotation
# typeKind: primitive
# typeName: String
# typeNamespace: nasl.core
# setter:
# concept: InputSetter
# placeholder: 'placeholder22'
# - name: feSelect
# title: 需要传入的值 todo默认值和类型需要改成数组
# defaultValue:
# concept: StringLiteral
# value: '默认值22'
# type:
# concept: TypeAnnotation
# typeKind: primitive
# typeName: String
# typeNamespace: nasl.core
# setter:
# concept: EnumSelectSetter
# options:
# - title: 页面跳转,
# value: destination
# - title: 下载链接,
# value: download
# multiple

103 changes: 103 additions & 0 deletions packages/cust/cust_anno_permission/annotations/feAnnotation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

function fetchData() {
return new Promise(async (resolve, reject) => {
if (!window.annotationAllData) {
console.log('正在请求');
sleep(500).then(res => {
console.log('等待结束');
resolve(fetchData())
})
}else if (window.annotationAllData) {
let {entityAll,logicAll} = window.annotationAllData
let mylogicAnno = logicAll.find(it=>it.annotationName==="DataPermissionLogicAnnotation")
let myEntityAnno = entityAll.find(it=>it.annotationName==="EntityPermissionAnnotation")
let data = {
entityAll:myEntityAnno&&myEntityAnno.entityList||[],
logicAll: mylogicAnno&&mylogicAnno.logicList || [],
}
resolve(data);
}
});
}
/**
* @param {string} el <false> 这是一个描述
* @param {string} binding <false> 这是一个描述
* @param {string} vnode <false> 这是一个描述
* @param {string} oldVnode <false> 这是一个描述
* @returns {string} result
*/
// 一个注解对应一个逻辑 一个yaml
// '["true","`默认值22`"]' 函数入参是按 anno.prop 的声明顺序
export default function (el, binding, vnode, oldVnode) {
// api + 实体和ViewEle 的映射关系
fetchData()
.then(data => {
console.log('Data:', data);
// data.entityAll.map(entity => {
// let entityName = Object.keys(entity)[0]
// console.log('entityName: ', entityName);
// let entityProps = entity[entityName]
// let noneList = entityProps
// .filter(p => p.columnRuleType === 'none')
// .map(p => p.propertyName)
// console.log('noneList: ', noneList);
// })
let annotationAllData = JSON.parse(binding.value.replace(/'/g, '"'));
let visible = true
annotationAllData && annotationAllData.dataRefList && annotationAllData.dataRefList.map(ref => {
console.log('ref: ', ref);
// propName
// "name"
// typeName
// "Entity1"
// typeNamespace
// "app.dataSources.defaultDS.entities"
let enKey
let list
if (ref.typeNamespace.includes('app.dataSources')) {
let ds = ref.typeNamespace.split('.')[2]
enKey = `${ds}.${ref.typeName}`
list = data && data.entityAll
}
if (ref.typeNamespace.includes('app.logics')) {
// let ds = ref.typeNamespace.split('.')[2]
// todo
enKey = `${ref.typeName}`
list = data && data.logicAll
}
// let entityItem = list.find(entity => {
// let entityName = Object.keys(entity)[0]
// return entityName === enKey
// })
let enProps = list[enKey]
if (enProps) {
// let enProps = entityItem[enKey]
if (enProps) {
// 此处假定逻辑返回的数据结构为多叉树 组件只能绑定叶子节点: 否则要比较 a.b.c a.b 的关系
let enProp = enProps.find(p => p.propertyName === ref.propName)
if (enProp) {
visible = enProp.columnRuleType !== 'none'

}
}
}
// propName: entityPropName
})
if (el.__vue__ && el.__vue__.$options.name === 'u-table-view-column') {
el.__vue__.currentHidden = !visible;
}
else {
el && (el.style.display = visible ? '' : 'none');
}
console.log('前端注解 执行: ', annotationAllData, binding, vnode, oldVnode);
})
.catch(error => {
console.error('Error:', error);
});

}




14 changes: 14 additions & 0 deletions packages/cust/cust_anno_permission/annotations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const $libraryName = 'lcap-fe-annotation-data-permission'

const UtilsLogics = {}
import feAnnotation from './feAnnotation'
// LOGIC IMPORTS

UtilsLogics.install = function (Vue, option = {}) {
Vue.prototype.$library = Vue.prototype.$library || {}
Vue.prototype.$library[`${$libraryName}`] = {}
Vue.prototype.$library[`${$libraryName}`].feAnnotation=feAnnotation
// LOGIC USE
}

export default UtilsLogics
6 changes: 6 additions & 0 deletions packages/cust/cust_anno_permission/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import UtilsLogics from './annotations';
// COMPONENT IMPORTS
export {
UtilsLogics,
// COMPONENT EXPORTS
};
6 changes: 6 additions & 0 deletions packages/cust/cust_anno_permission/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Plugin-Version: 1.0.0
Library-Type: Frontend
Metadata-File: usage.json
packages/extension/[email protected]/dist-theme/demo.html: dist-theme/demo.html
packages/extension/[email protected]/dist-theme/index.js: dist-theme/index.js
packages/extension/[email protected]/dist-theme/index.js.map: dist-theme/index.js.map
Loading
Loading