w-web-perm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.github/workflows/ci-test.yml +24 -0
- package/.jsdoc +25 -0
- package/.vscode/launch.json +21 -0
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +15 -0
- package/dist/css/app.79b4b59b.css +1 -0
- package/dist/css/chunk-vendors.65775501.css +5 -0
- package/dist/index.tmp +1 -0
- package/dist/js/app-legacy.954e168c.js +2 -0
- package/dist/js/app-legacy.954e168c.js.map +1 -0
- package/dist/js/app.954e168c.js +2 -0
- package/dist/js/app.954e168c.js.map +1 -0
- package/dist/js/chunk-vendors-legacy.f5f1a231.js +13 -0
- package/dist/js/chunk-vendors-legacy.f5f1a231.js.map +1 -0
- package/dist/js/chunk-vendors.f5f1a231.js +13 -0
- package/dist/js/chunk-vendors.f5f1a231.js.map +1 -0
- package/dist/w-web-perm.umd.js +7 -0
- package/dist/w-web-perm.umd.js.map +1 -0
- package/docs/WWebPerm.html +826 -0
- package/docs/WWebPerm.mjs.html +558 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/index.html +84 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/g.getSettings.mjs +17 -0
- package/g.mDb.mjs +10 -0
- package/g.mInitialTestData.mjs +20 -0
- package/g.mOrm.mjs +24 -0
- package/package.json +75 -0
- package/public/index.html +23 -0
- package/server/WWebPerm.mjs +486 -0
- package/src/App.vue +153 -0
- package/src/components/Common/CheckYes.vue +85 -0
- package/src/components/Common/CheckYesNo.vue +91 -0
- package/src/components/Common/LabelItem.vue +106 -0
- package/src/components/Common/LoadingWinBar.vue +87 -0
- package/src/components/Layout.vue +152 -0
- package/src/components/LayoutContent.vue +246 -0
- package/src/components/LayoutContentGroups.vue +664 -0
- package/src/components/LayoutContentTargets.vue +538 -0
- package/src/components/LayoutContentUsers.vue +493 -0
- package/src/components/LayoutState.vue +91 -0
- package/src/components/VeUser.vue +453 -0
- package/src/components/ruleGroup.vue +667 -0
- package/src/main.js +103 -0
- package/src/perm.mjs +61 -0
- package/src/plugins/mDataSelectorSchema.mjs +30 -0
- package/src/plugins/mDataSupport.mjs +66 -0
- package/src/plugins/mShare.mjs +366 -0
- package/src/plugins/mUI.mjs +229 -0
- package/src/plugins/mVuetify.mjs +12 -0
- package/src/schema/gi.mjs +8 -0
- package/src/schema/index.mjs +20 -0
- package/src/schema/tables/ruleGroups.mjs +100 -0
- package/src/schema/tables/targets.mjs +100 -0
- package/src/schema/tables/users.mjs +125 -0
- package/src/store/actions.mjs +1 -0
- package/src/store/getters.mjs +1 -0
- package/src/store/index.mjs +25 -0
- package/src/store/mutations.mjs +201 -0
- package/src/store/types.mjs +15 -0
- package/srv.mjs +52 -0
- package/tableTags-web-perm.json +1 -0
- package/test/all.test.mjs +10 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistRollup.mjs +36 -0
- package/toolg/genEntry.mjs +23 -0
- package/toolg/modifyReadme.mjs +4 -0
- package/vue.config.js +15 -0
package/src/main.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import get from 'lodash/get'
|
|
2
|
+
// import '@babel/polyfill' //需提供Vuetify的Symbol等API
|
|
3
|
+
// import 'core-js/stable' //需提供Vuetify的Symbol等API, 官網說使用transpileDependencies但不夠, 改用之前提到的@babel/polyfill會被提示已廢棄, 改使用給webpack的polyfill方式才行
|
|
4
|
+
// import 'regenerator-runtime/runtime'
|
|
5
|
+
// import 'intersection-observer' //需供Vuetify的Intersection Observer, 專案內有使用v-intersect才需引入, 而w-component-vue沒用v-intersect
|
|
6
|
+
import Vue from 'vue'
|
|
7
|
+
import WServHapiClient from 'w-serv-hapi/src/WServHapiClient.mjs'
|
|
8
|
+
import WAlert from 'w-component-vue/src/components/WAlert.mjs'
|
|
9
|
+
import domMutation from 'w-component-vue/src/js/domMutation.mjs'
|
|
10
|
+
import domResize from 'w-component-vue/src/js/domResize.mjs'
|
|
11
|
+
import domDragDrop from 'w-component-vue/src/js/domDragDrop.mjs'
|
|
12
|
+
import App from './App.vue'
|
|
13
|
+
import store from './store/index.mjs'
|
|
14
|
+
import mVuetify from './plugins/mVuetify.mjs'
|
|
15
|
+
import ui from './plugins/mUI.mjs'
|
|
16
|
+
import mDataSelectorSchema from './plugins/mDataSelectorSchema.mjs'
|
|
17
|
+
import mDataSupport from './plugins/mDataSupport.mjs'
|
|
18
|
+
import * as s from './plugins/mShare.mjs'
|
|
19
|
+
import ds from './schema/index.mjs'
|
|
20
|
+
// console.log('globalState', globalState)
|
|
21
|
+
// console.log('ds', ds)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
//不提示vue產品
|
|
25
|
+
Vue.config.productionTip = false
|
|
26
|
+
|
|
27
|
+
//$alert
|
|
28
|
+
Vue.prototype.$alert = function() {
|
|
29
|
+
let [msg, type] = arguments
|
|
30
|
+
console.log(msg, type)
|
|
31
|
+
if (msg !== 'close') {
|
|
32
|
+
WAlert(msg, type)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//dssm
|
|
37
|
+
let dssm = mDataSelectorSchema(ds)
|
|
38
|
+
|
|
39
|
+
//dspt
|
|
40
|
+
let dspt = mDataSupport(Vue.prototype)
|
|
41
|
+
|
|
42
|
+
//prototype
|
|
43
|
+
Vue.prototype.$ui = ui
|
|
44
|
+
Vue.prototype.$t = ui.getKpText
|
|
45
|
+
Vue.prototype.$s = s
|
|
46
|
+
Vue.prototype.$dssm = dssm
|
|
47
|
+
Vue.prototype.$dspt = dspt
|
|
48
|
+
// Vue.prototype.$ds = ds
|
|
49
|
+
Vue.prototype.$dg = {}
|
|
50
|
+
|
|
51
|
+
//directive
|
|
52
|
+
Vue.directive('domresize', domResize())
|
|
53
|
+
Vue.directive('dommutation', domMutation())
|
|
54
|
+
Vue.directive('domdragdrop', domDragDrop())
|
|
55
|
+
|
|
56
|
+
//WServHapiClient
|
|
57
|
+
let bFirstSync = false
|
|
58
|
+
WServHapiClient({
|
|
59
|
+
showLog: false,
|
|
60
|
+
getUrl: () => {
|
|
61
|
+
return window.location.origin + window.location.pathname
|
|
62
|
+
},
|
|
63
|
+
useWaitToken: true,
|
|
64
|
+
getToken: () => {
|
|
65
|
+
let token = get(Vue.prototype, `$store.state.userToken`, '')
|
|
66
|
+
// console.log('getToken', token)
|
|
67
|
+
return token
|
|
68
|
+
},
|
|
69
|
+
getServerMethods: (_fapi) => {
|
|
70
|
+
console.log('$fapi', _fapi)
|
|
71
|
+
Vue.prototype.$fapi = _fapi
|
|
72
|
+
_fapi.getWebInfor() //已有fapi時優先取得web資訊
|
|
73
|
+
.then((wi) => {
|
|
74
|
+
console.log('$fapi getWebInfor', wi)
|
|
75
|
+
Vue.prototype.$store.commit(Vue.prototype.$store.types.UpdateWebInfor, wi)
|
|
76
|
+
ui.setLang() //因更新webInfor得要重刷語系才能依照語言取得顯示文字
|
|
77
|
+
})
|
|
78
|
+
.catch((err) => {
|
|
79
|
+
console.log(err)
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
recvData: (r) => {
|
|
83
|
+
console.log('sync data', r.tableName, r.data)
|
|
84
|
+
Vue.prototype.$store.commit(Vue.prototype.$store.types.UpdateTableData, r)
|
|
85
|
+
},
|
|
86
|
+
getAfterUpdateTableTags: (r) => {
|
|
87
|
+
// console.log('getAfterUpdateTableTags', r, 'needToRefresh', JSON.stringify(r.oldTableTags) !== JSON.stringify(r.newTableTags))
|
|
88
|
+
if (bFirstSync) {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
bFirstSync = true
|
|
92
|
+
console.log('first-sync')
|
|
93
|
+
Vue.prototype.$store.commit(Vue.prototype.$store.types.UpdateSyncState, true)
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
//new
|
|
98
|
+
new Vue({
|
|
99
|
+
vuetify: mVuetify,
|
|
100
|
+
store,
|
|
101
|
+
render: h => h(App)
|
|
102
|
+
}).$mount('#app')
|
|
103
|
+
|
package/src/perm.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
3
|
+
import genPm from 'wsemi/src/genPm.mjs'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
let _url = ''
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function iniPerm(url) {
|
|
10
|
+
_url = url
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async function getPerm(token) {
|
|
15
|
+
|
|
16
|
+
//check
|
|
17
|
+
if (!isestr(_url)) {
|
|
18
|
+
throw new Error(`invalid url, need to use iniPerm to set url`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//pm
|
|
22
|
+
let pm = genPm()
|
|
23
|
+
|
|
24
|
+
//url
|
|
25
|
+
let url = `${_url}?token=${token}`
|
|
26
|
+
|
|
27
|
+
//axios
|
|
28
|
+
await axios({
|
|
29
|
+
method: 'get',
|
|
30
|
+
url,
|
|
31
|
+
// headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
32
|
+
// data: rin,
|
|
33
|
+
})
|
|
34
|
+
.then((res) => {
|
|
35
|
+
// console.log(res)
|
|
36
|
+
let r = {
|
|
37
|
+
msg: '成功取得使用者權限',
|
|
38
|
+
res,
|
|
39
|
+
}
|
|
40
|
+
pm.resolve(r)
|
|
41
|
+
})
|
|
42
|
+
.catch((err) => {
|
|
43
|
+
// console.log(err)
|
|
44
|
+
let r = {
|
|
45
|
+
msg: '取得使用者權限發生錯誤',
|
|
46
|
+
res: err,
|
|
47
|
+
}
|
|
48
|
+
pm.reject(r)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return pm
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
let perm = {
|
|
56
|
+
iniPerm,
|
|
57
|
+
getPerm,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export default perm
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import get from 'lodash/get'
|
|
2
|
+
import find from 'lodash/find'
|
|
3
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function mDataSelectorSchema(ds, opt = {}) {
|
|
7
|
+
|
|
8
|
+
function getTableInforBy(keyFind, valueFind, keyPick) {
|
|
9
|
+
let r = find(ds, { [keyFind]: valueFind })
|
|
10
|
+
if (!r) {
|
|
11
|
+
r = ''
|
|
12
|
+
}
|
|
13
|
+
if (isestr(keyPick)) {
|
|
14
|
+
r = get(r, keyPick, '')
|
|
15
|
+
}
|
|
16
|
+
return r
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getTableChtByKey(valueFind) {
|
|
20
|
+
return getTableInforBy('keyTable', valueFind, 'tableNameCht')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
getTableInforBy,
|
|
25
|
+
getTableChtByKey,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export default mDataSelectorSchema
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// import min from 'lodash/min'
|
|
2
|
+
// import size from 'lodash/size'
|
|
3
|
+
// import take from 'lodash/take'
|
|
4
|
+
// import isEqual from 'lodash/isEqual'
|
|
5
|
+
// import uniq from 'lodash/uniq'
|
|
6
|
+
// import set from 'lodash/set'
|
|
7
|
+
// import get from 'lodash/get'
|
|
8
|
+
// import each from 'lodash/each'
|
|
9
|
+
// import map from 'lodash/map'
|
|
10
|
+
// import filter from 'lodash/filter'
|
|
11
|
+
// import last from 'lodash/last'
|
|
12
|
+
// import split from 'lodash/split'
|
|
13
|
+
// import join from 'lodash/join'
|
|
14
|
+
// import drop from 'lodash/drop'
|
|
15
|
+
// import dropRight from 'lodash/dropRight'
|
|
16
|
+
// import groupBy from 'lodash/groupBy'
|
|
17
|
+
// import sortBy from 'lodash/sortBy'
|
|
18
|
+
// import cloneDeep from 'lodash/cloneDeep'
|
|
19
|
+
// import cint from 'wsemi/src/cint.mjs'
|
|
20
|
+
// import delay from 'wsemi/src/delay.mjs'
|
|
21
|
+
// import isarr from 'wsemi/src/isarr.mjs'
|
|
22
|
+
// import isestr from 'wsemi/src/isestr.mjs'
|
|
23
|
+
// import isfun from 'wsemi/src/isfun.mjs'
|
|
24
|
+
// import iseobj from 'wsemi/src/iseobj.mjs'
|
|
25
|
+
// import isearr from 'wsemi/src/isearr.mjs'
|
|
26
|
+
// import isEle from 'wsemi/src/isEle.mjs'
|
|
27
|
+
// import strleft from 'wsemi/src/strleft.mjs'
|
|
28
|
+
// import strdelleft from 'wsemi/src/strdelleft.mjs'
|
|
29
|
+
// import sep from 'wsemi/src/sep.mjs'
|
|
30
|
+
// import aes2str from 'wsemi/src/aes2str.mjs'
|
|
31
|
+
// import str2aes from 'wsemi/src/str2aes.mjs'
|
|
32
|
+
// import haskey from 'wsemi/src/haskey.mjs'
|
|
33
|
+
// import genPm from 'wsemi/src/genPm.mjs'
|
|
34
|
+
// import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
35
|
+
// import waitFun from 'wsemi/src/waitFun.mjs'
|
|
36
|
+
// import browserView from 'wsemi/src/browserView.mjs'
|
|
37
|
+
// import arrHas from 'wsemi/src/arrHas.mjs'
|
|
38
|
+
// import arrSort from 'wsemi/src/arrSort.mjs'
|
|
39
|
+
// import arrInsert from 'wsemi/src/arrInsert.mjs'
|
|
40
|
+
// import replace from 'wsemi/src/replace.mjs'
|
|
41
|
+
// import timemsTZ2past from 'wsemi/src/timemsTZ2past.mjs'
|
|
42
|
+
// import convertToTree from 'wsemi/src/convertToTree.mjs'
|
|
43
|
+
// import html2picDyn from 'wsemi/src/html2picDyn.mjs'
|
|
44
|
+
// import urlParse from 'wsemi/src/urlParse.mjs'
|
|
45
|
+
// import domConvertToPicDyn from 'wsemi/src/domConvertToPicDyn.mjs'
|
|
46
|
+
// import ltdtkeysheads2mat from 'wsemi/src/ltdtkeysheads2mat.mjs'
|
|
47
|
+
// import downloadFileFromB64 from 'wsemi/src/downloadFileFromB64.mjs'
|
|
48
|
+
// import downloadExcelFileFromDataDyn from 'wsemi/src/downloadExcelFileFromDataDyn.mjs'
|
|
49
|
+
// import getFileAccept from 'wsemi/src/getFileAccept.mjs'
|
|
50
|
+
// import downloadFileFromU8Arr from 'wsemi/src/downloadFileFromU8Arr.mjs'
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
function mDataSupport(vo, opt = {}) {
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
|
|
58
|
+
// mdCheckKeyInd,
|
|
59
|
+
// mdGetTextByKey,
|
|
60
|
+
// mdGetTextByKeyIndAndKey,
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export default mDataSupport
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
//前後端共用函數區
|
|
2
|
+
// import min from 'lodash/min'
|
|
3
|
+
// import size from 'lodash/size'
|
|
4
|
+
// import take from 'lodash/take'
|
|
5
|
+
// import isEqual from 'lodash/isEqual'
|
|
6
|
+
import uniq from 'lodash/uniq'
|
|
7
|
+
// import set from 'lodash/set'
|
|
8
|
+
import get from 'lodash/get'
|
|
9
|
+
import each from 'lodash/each'
|
|
10
|
+
import map from 'lodash/map'
|
|
11
|
+
import find from 'lodash/find'
|
|
12
|
+
import filter from 'lodash/filter'
|
|
13
|
+
// import last from 'lodash/last'
|
|
14
|
+
// import size from 'lodash/size'
|
|
15
|
+
import split from 'lodash/split'
|
|
16
|
+
import join from 'lodash/join'
|
|
17
|
+
import cloneDeep from 'lodash/cloneDeep'
|
|
18
|
+
import takeRight from 'lodash/takeRight'
|
|
19
|
+
import dropRight from 'lodash/dropRight'
|
|
20
|
+
import sortBy from 'lodash/sortBy'
|
|
21
|
+
import sep from 'wsemi/src/sep.mjs'
|
|
22
|
+
import isarr from 'wsemi/src/isarr.mjs'
|
|
23
|
+
import isstr from 'wsemi/src/isstr.mjs'
|
|
24
|
+
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
25
|
+
import haskey from 'wsemi/src/haskey.mjs'
|
|
26
|
+
import composeToTree from 'wsemi/src/composeToTree.mjs'
|
|
27
|
+
// import getFileAccept from 'wsemi/src/getFileAccept.mjs'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// function atSep(attachmentsIds) {
|
|
31
|
+
|
|
32
|
+
// //ts
|
|
33
|
+
// let ts = sep(attachmentsIds, ';')
|
|
34
|
+
|
|
35
|
+
// return ts
|
|
36
|
+
// }
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// function atJoin(ts) {
|
|
40
|
+
|
|
41
|
+
// //uniq
|
|
42
|
+
// ts = uniq(ts)
|
|
43
|
+
|
|
44
|
+
// //str
|
|
45
|
+
// let str = join(ts, ';')
|
|
46
|
+
|
|
47
|
+
// return str
|
|
48
|
+
// }
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// function atParse(attachmentsIds) {
|
|
52
|
+
|
|
53
|
+
// //ts
|
|
54
|
+
// let ts = atSep(attachmentsIds)
|
|
55
|
+
|
|
56
|
+
// //ids
|
|
57
|
+
// let ids = map(ts, (v) => {
|
|
58
|
+
// let s = sep(v, '@')
|
|
59
|
+
// let table = get(s, 0, '')
|
|
60
|
+
// let id = get(s, 1, '')
|
|
61
|
+
// if (table === '') {
|
|
62
|
+
// console.log('atParse: invalid table in attachmentsIds', attachmentsIds)
|
|
63
|
+
// }
|
|
64
|
+
// if (id === '') {
|
|
65
|
+
// console.log('atParse: invalid id in attachmentsIds', attachmentsIds)
|
|
66
|
+
// }
|
|
67
|
+
// return {
|
|
68
|
+
// table,
|
|
69
|
+
// id,
|
|
70
|
+
// }
|
|
71
|
+
// })
|
|
72
|
+
|
|
73
|
+
// return ids
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
// function atRemove(inp, removeId, opt = {}) {
|
|
78
|
+
|
|
79
|
+
// //removeId
|
|
80
|
+
// if (!isstr(removeId)) {
|
|
81
|
+
// removeId = ''
|
|
82
|
+
// }
|
|
83
|
+
// if (removeId.indexOf('@') >= 0) {
|
|
84
|
+
// removeId = split(removeId, '@')[1] //取後面id
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// //ids
|
|
88
|
+
// let ids = []
|
|
89
|
+
// let returnTypeTemp = ''
|
|
90
|
+
// if (isarr(inp)) {
|
|
91
|
+
// ids = inp
|
|
92
|
+
// returnTypeTemp = 'array'
|
|
93
|
+
// }
|
|
94
|
+
// else if (isstr(inp)) {
|
|
95
|
+
// ids = atParse(inp)
|
|
96
|
+
// returnTypeTemp = 'string'
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// //returnType
|
|
100
|
+
// let returnType = get(opt, 'returnType', null)
|
|
101
|
+
// if (returnType !== 'array' && returnType !== 'string') {
|
|
102
|
+
// returnType = returnTypeTemp
|
|
103
|
+
// }
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// //filter
|
|
107
|
+
// ids = filter(ids, (v) => {
|
|
108
|
+
// return v.id !== removeId
|
|
109
|
+
// })
|
|
110
|
+
|
|
111
|
+
// if (returnType === 'array') {
|
|
112
|
+
// return ids
|
|
113
|
+
// }
|
|
114
|
+
// return atMerge(ids)
|
|
115
|
+
// }
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// function atMerge(ids) {
|
|
119
|
+
|
|
120
|
+
// //ts
|
|
121
|
+
// let ts = map(ids, (v) => {
|
|
122
|
+
// let table = get(v, 'table', '')
|
|
123
|
+
// let id = get(v, 'id', '')
|
|
124
|
+
// if (table === '') {
|
|
125
|
+
// console.log('atMerge: invalid table in ids', ids)
|
|
126
|
+
// }
|
|
127
|
+
// if (id === '') {
|
|
128
|
+
// console.log('atMerge: invalid id in ids', ids)
|
|
129
|
+
// }
|
|
130
|
+
// return `${table}@${id}`
|
|
131
|
+
// })
|
|
132
|
+
|
|
133
|
+
// return atJoin(ts)
|
|
134
|
+
// }
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
// function isNumOrEng(str) {
|
|
138
|
+
// let regExp = /^[\d|a-zA-Z]+$/
|
|
139
|
+
// if (regExp.test(str)) {
|
|
140
|
+
// return true
|
|
141
|
+
// }
|
|
142
|
+
// else {
|
|
143
|
+
// return false
|
|
144
|
+
// }
|
|
145
|
+
// }
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// function extractFileType(fileName, fileType) {
|
|
149
|
+
// let r = ''
|
|
150
|
+
|
|
151
|
+
// //find
|
|
152
|
+
// let ar = getFileAccept()
|
|
153
|
+
// for (let i = 0; i < ar.length; i++) {
|
|
154
|
+
// if (ar[i].acp === fileType) {
|
|
155
|
+
// return ar[i].name
|
|
156
|
+
// }
|
|
157
|
+
// }
|
|
158
|
+
|
|
159
|
+
// //from name ext
|
|
160
|
+
// let s = split(fileName, '.')
|
|
161
|
+
// if (size(s) > 1) {
|
|
162
|
+
// return last(s)
|
|
163
|
+
// }
|
|
164
|
+
|
|
165
|
+
// return r
|
|
166
|
+
// }
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
function getAllBlocks(targets) {
|
|
170
|
+
|
|
171
|
+
//rs
|
|
172
|
+
let rs = map(targets, (v) => {
|
|
173
|
+
|
|
174
|
+
//text, parentId
|
|
175
|
+
let s = sep(v.id, '.')
|
|
176
|
+
let text = get(takeRight(s), 0) //取最後節點
|
|
177
|
+
s = dropRight(s, 1)
|
|
178
|
+
let parentId = join(s, '.') //取父節點
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
...v,
|
|
182
|
+
idTemp: v.id,
|
|
183
|
+
parentId,
|
|
184
|
+
text,
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
//sortBy
|
|
189
|
+
rs = sortBy(rs, 'order')
|
|
190
|
+
|
|
191
|
+
return rs
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
function getTreeBlocks(targets) {
|
|
196
|
+
|
|
197
|
+
//getAllBlocks
|
|
198
|
+
let blocks = getAllBlocks(targets)
|
|
199
|
+
|
|
200
|
+
//opt
|
|
201
|
+
let opt = {
|
|
202
|
+
bindKey: 'id',
|
|
203
|
+
bindParent: 'parentId',
|
|
204
|
+
bindChildren: 'children',
|
|
205
|
+
saveExtProps: true,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//composeToTree
|
|
209
|
+
let r
|
|
210
|
+
try {
|
|
211
|
+
r = composeToTree(blocks, opt)
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
console.log(err)
|
|
215
|
+
}
|
|
216
|
+
// console.log('treeBlocks', cloneDeep(r))
|
|
217
|
+
|
|
218
|
+
return r
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
function getUserGroups(user, ruleGroups) {
|
|
223
|
+
|
|
224
|
+
//userGroups
|
|
225
|
+
let ruleGroupsIds = get(user, 'ruleGroupsIds', '')
|
|
226
|
+
|
|
227
|
+
//sep
|
|
228
|
+
let s = sep(ruleGroupsIds, ';')
|
|
229
|
+
|
|
230
|
+
//gs
|
|
231
|
+
let gs = []
|
|
232
|
+
each(s, (id) => {
|
|
233
|
+
let g = find(ruleGroups, { id })
|
|
234
|
+
if (iseobj(g)) {
|
|
235
|
+
gs.push(g)
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
//add rules
|
|
240
|
+
gs = map(gs, (g) => {
|
|
241
|
+
let rules = JSON.parse(g.crules)
|
|
242
|
+
g.rules = rules
|
|
243
|
+
return g
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
return gs
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
function getTargetsByGroup(targets, group) {
|
|
251
|
+
|
|
252
|
+
//cloneDeep
|
|
253
|
+
targets = cloneDeep(targets)
|
|
254
|
+
|
|
255
|
+
//sortBy
|
|
256
|
+
targets = sortBy(targets, 'order')
|
|
257
|
+
|
|
258
|
+
//cloneDeep
|
|
259
|
+
group = cloneDeep(group)
|
|
260
|
+
|
|
261
|
+
//rules
|
|
262
|
+
let rules = JSON.parse(group.crules)
|
|
263
|
+
|
|
264
|
+
//rulesDisplay
|
|
265
|
+
let rulesDisplay = {}
|
|
266
|
+
let ks = ['show', 'active']
|
|
267
|
+
each(ks, (k) => {
|
|
268
|
+
|
|
269
|
+
//___all___
|
|
270
|
+
let def = get(rules, `___all___.${k}`)
|
|
271
|
+
def = (def === 'y') ? 'y' : 'n'
|
|
272
|
+
|
|
273
|
+
//other props
|
|
274
|
+
each(targets, (v) => {
|
|
275
|
+
|
|
276
|
+
//krule
|
|
277
|
+
let krule = v.id
|
|
278
|
+
|
|
279
|
+
//check
|
|
280
|
+
if (!rulesDisplay[krule]) {
|
|
281
|
+
rulesDisplay[krule] = {}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
//rule
|
|
285
|
+
let rule = rules[krule]
|
|
286
|
+
|
|
287
|
+
//r
|
|
288
|
+
let r = null
|
|
289
|
+
|
|
290
|
+
//b
|
|
291
|
+
let b = get(rule, `${k}`)
|
|
292
|
+
if (b === 'y' || b === 'n') {
|
|
293
|
+
r = b
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
r = def
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
//save
|
|
300
|
+
rulesDisplay[krule][k] = r //因krule內含有「.」故不能用set
|
|
301
|
+
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
})
|
|
305
|
+
// console.log('rulesDisplay', rulesDisplay)
|
|
306
|
+
|
|
307
|
+
return rulesDisplay
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
function getUserRules(user, ruleGroups, targets) {
|
|
312
|
+
|
|
313
|
+
//getUserGroups
|
|
314
|
+
let gs = getUserGroups(user, ruleGroups)
|
|
315
|
+
// console.log('gs', gs)
|
|
316
|
+
|
|
317
|
+
//getTargetsByGroup
|
|
318
|
+
let rulesDisplay = {}
|
|
319
|
+
each(gs, (g) => {
|
|
320
|
+
let r = getTargetsByGroup(targets, g)
|
|
321
|
+
each(r, (v, k) => {
|
|
322
|
+
|
|
323
|
+
//check
|
|
324
|
+
if (!haskey(rulesDisplay, k)) {
|
|
325
|
+
rulesDisplay[k] = {}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
//merge
|
|
329
|
+
let ks = ['show', 'active']
|
|
330
|
+
each(ks, (kk) => {
|
|
331
|
+
let bOld = rulesDisplay[k][kk]
|
|
332
|
+
let bNew = r[k][kk]
|
|
333
|
+
if (bOld === 'y') {
|
|
334
|
+
//不用覆寫
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
//需覆寫
|
|
338
|
+
if (bNew === 'y') {
|
|
339
|
+
rulesDisplay[k][kk] = 'y'
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
rulesDisplay[k][kk] = 'n'
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
// console.log('rulesDisplay', rulesDisplay)
|
|
350
|
+
|
|
351
|
+
return rulesDisplay
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
export {
|
|
356
|
+
// atSep,
|
|
357
|
+
// atJoin,
|
|
358
|
+
// atParse,
|
|
359
|
+
// atMerge,
|
|
360
|
+
// atRemove,
|
|
361
|
+
// getAllBlocks,
|
|
362
|
+
getTreeBlocks,
|
|
363
|
+
// getUserGroups,
|
|
364
|
+
// getTargetsByGroup,
|
|
365
|
+
getUserRules
|
|
366
|
+
}
|