adtec-core-package 0.2.8 → 0.3.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/README.en.md +36 -36
- package/package.json +2 -2
- package/src/api/BasicApi.ts +17 -0
- package/src/api/DocumentApi.ts +18 -18
- package/src/api/SysDictCacheApi.ts +26 -28
- package/src/api/SysUserApi.ts +35 -0
- package/src/api/framework.ts +12 -12
- package/src/assets/style/ant.scss +19 -19
- package/src/assets/style/index.less +180 -180
- package/src/components/ElFlex/ElFlex.vue +297 -297
- package/src/components/Search/ElSearch.vue +149 -132
- package/src/components/Table/ElTableColumnEdit.vue +218 -218
- package/src/components/Title/ElTitle.vue +49 -49
- package/src/components/autoToolTip/{index.vue → ElAutoToolTip.vue} +61 -61
- package/src/components/business/userSelect.vue +412 -0
- package/src/components/upload/FileView.vue +158 -158
- package/src/components/upload/FileViewComponents.vue +57 -57
- package/src/config/ElementPlusConfig.ts +95 -95
- package/src/css/elementUI/autocomplete.scss +89 -89
- package/src/css/elementUI/common/var.scss +1549 -1549
- package/src/css/elementUI/date-picker/picker.scss +219 -219
- package/src/css/elementUI/drawer.scss +164 -164
- package/src/css/elementUI/table.scss +694 -694
- package/src/css/elementUI/tabs.scss +659 -659
- package/src/directives/vKeydown.ts +93 -93
- package/src/hooks/useDictHooks.ts +77 -78
- package/src/hooks/useFileView.ts +34 -34
- package/src/hooks/useMessageHooks.ts +132 -132
- package/src/hooks/useResetRefHooks.ts +19 -19
- package/src/interface/BaseEntity.ts +28 -28
- package/src/interface/IMdmDept.ts +82 -0
- package/src/interface/IOrgDeptInfo.ts +12 -0
- package/src/interface/ISysDictDataCacheVo.ts +46 -46
- package/src/interface/ISysDictType.ts +37 -37
- package/src/interface/ISysMenuDataVo.ts +22 -22
- package/src/interface/ISysMenuInfoVo.ts +83 -83
- package/src/interface/ISysMenuOperationVo.ts +21 -21
- package/src/interface/ISysUploadFiles.ts +16 -16
- package/src/interface/ISysUserInfo.ts +70 -0
- package/src/interface/IUserPermissionVo.ts +34 -34
- package/src/interface/Message.ts +69 -69
- package/src/interface/PageData.ts +17 -17
- package/src/interface/ResponseData.ts +16 -16
- package/src/interface/dictMapType.ts +11 -0
- package/src/interface/enum/MessageEnum.ts +41 -41
- package/src/mixin/globalMixin.ts +7 -4
- package/src/packages/index.ts +18 -18
- package/src/packages/text.vue +13 -13
- package/src/plugins/plugins.ts +12 -12
- package/src/stores/dictStore.ts +27 -27
- package/src/stores/messageStore.ts +49 -49
- package/src/stores/storeConfig.ts +23 -23
- package/src/stores/userInfoStore.ts +31 -31
- package/src/utils/AxiosConfig.ts +216 -216
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create by丁盼
|
|
3
|
-
* 说明: v-keydown
|
|
4
|
-
* 创建时间: 2024/12/12 15:51
|
|
5
|
-
* 修改时间: 2024/12/12 15:51
|
|
6
|
-
*/
|
|
7
|
-
import { useEventBus } from '@vueuse/core'
|
|
8
|
-
const vKeydown = {
|
|
9
|
-
beforeMount: (el: HTMLElement) => {
|
|
10
|
-
el.addEventListener('keydown', (e) => {
|
|
11
|
-
if (e.key === 'Tab') {
|
|
12
|
-
const el = e.target as HTMLElement
|
|
13
|
-
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {
|
|
14
|
-
//查找上级DIV 节点 取消编辑
|
|
15
|
-
let b = true
|
|
16
|
-
let i = 0
|
|
17
|
-
let parent: any = el
|
|
18
|
-
while (b) {
|
|
19
|
-
parent = parent.parentElement
|
|
20
|
-
if (parent.className.indexOf('el-table-column-edit') > -1) {
|
|
21
|
-
b = false
|
|
22
|
-
} else {
|
|
23
|
-
i++
|
|
24
|
-
if (i > 5) {
|
|
25
|
-
b = false
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const bus = useEventBus<string>(parent.id)
|
|
30
|
-
bus.emit()
|
|
31
|
-
//寻找下一个编辑的单元格
|
|
32
|
-
//找到el-table__cell' 节点
|
|
33
|
-
b = true
|
|
34
|
-
i = 0
|
|
35
|
-
while (b) {
|
|
36
|
-
parent = parent.parentElement
|
|
37
|
-
if (parent.className.indexOf('el-table__cell') > -1) {
|
|
38
|
-
b = false
|
|
39
|
-
} else {
|
|
40
|
-
i++
|
|
41
|
-
if (i > 5) {
|
|
42
|
-
b = false
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
b = true
|
|
47
|
-
i = 0
|
|
48
|
-
while (b) {
|
|
49
|
-
if (parent.nextElementSibling) {
|
|
50
|
-
const input = parent.nextElementSibling.getElementsByClassName('el-table-column-edit')
|
|
51
|
-
if (input.length > 0) {
|
|
52
|
-
setTimeout(() => {
|
|
53
|
-
input[0].click()
|
|
54
|
-
}, 10)
|
|
55
|
-
b = false
|
|
56
|
-
e.stopPropagation()
|
|
57
|
-
return false
|
|
58
|
-
} else {
|
|
59
|
-
parent = parent.nextElementSibling
|
|
60
|
-
i++
|
|
61
|
-
if (i > 5) {
|
|
62
|
-
b = false
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
b = false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//如果当前行结束判断下一行数据
|
|
70
|
-
const tr = parent.parentNode.nextElementSibling
|
|
71
|
-
try {
|
|
72
|
-
for (let j = 0; j < tr.children.length; j++) {
|
|
73
|
-
const input = tr.children[j].getElementsByClassName('el-table-column-edit')
|
|
74
|
-
if (input.length > 0) {
|
|
75
|
-
setTimeout(() => {
|
|
76
|
-
input[0].click()
|
|
77
|
-
e.stopPropagation()
|
|
78
|
-
}, 10)
|
|
79
|
-
break
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
/* empty */
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
},
|
|
89
|
-
unmounted: (el: HTMLElement) => {
|
|
90
|
-
el.removeEventListener('keydown', () => {})
|
|
91
|
-
},
|
|
92
|
-
}
|
|
93
|
-
export default vKeydown
|
|
1
|
+
/**
|
|
2
|
+
* Create by丁盼
|
|
3
|
+
* 说明: v-keydown
|
|
4
|
+
* 创建时间: 2024/12/12 15:51
|
|
5
|
+
* 修改时间: 2024/12/12 15:51
|
|
6
|
+
*/
|
|
7
|
+
import { useEventBus } from '@vueuse/core'
|
|
8
|
+
const vKeydown = {
|
|
9
|
+
beforeMount: (el: HTMLElement) => {
|
|
10
|
+
el.addEventListener('keydown', (e) => {
|
|
11
|
+
if (e.key === 'Tab') {
|
|
12
|
+
const el = e.target as HTMLElement
|
|
13
|
+
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {
|
|
14
|
+
//查找上级DIV 节点 取消编辑
|
|
15
|
+
let b = true
|
|
16
|
+
let i = 0
|
|
17
|
+
let parent: any = el
|
|
18
|
+
while (b) {
|
|
19
|
+
parent = parent.parentElement
|
|
20
|
+
if (parent.className.indexOf('el-table-column-edit') > -1) {
|
|
21
|
+
b = false
|
|
22
|
+
} else {
|
|
23
|
+
i++
|
|
24
|
+
if (i > 5) {
|
|
25
|
+
b = false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const bus = useEventBus<string>(parent.id)
|
|
30
|
+
bus.emit()
|
|
31
|
+
//寻找下一个编辑的单元格
|
|
32
|
+
//找到el-table__cell' 节点
|
|
33
|
+
b = true
|
|
34
|
+
i = 0
|
|
35
|
+
while (b) {
|
|
36
|
+
parent = parent.parentElement
|
|
37
|
+
if (parent.className.indexOf('el-table__cell') > -1) {
|
|
38
|
+
b = false
|
|
39
|
+
} else {
|
|
40
|
+
i++
|
|
41
|
+
if (i > 5) {
|
|
42
|
+
b = false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
b = true
|
|
47
|
+
i = 0
|
|
48
|
+
while (b) {
|
|
49
|
+
if (parent.nextElementSibling) {
|
|
50
|
+
const input = parent.nextElementSibling.getElementsByClassName('el-table-column-edit')
|
|
51
|
+
if (input.length > 0) {
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
input[0].click()
|
|
54
|
+
}, 10)
|
|
55
|
+
b = false
|
|
56
|
+
e.stopPropagation()
|
|
57
|
+
return false
|
|
58
|
+
} else {
|
|
59
|
+
parent = parent.nextElementSibling
|
|
60
|
+
i++
|
|
61
|
+
if (i > 5) {
|
|
62
|
+
b = false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
b = false
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//如果当前行结束判断下一行数据
|
|
70
|
+
const tr = parent.parentNode.nextElementSibling
|
|
71
|
+
try {
|
|
72
|
+
for (let j = 0; j < tr.children.length; j++) {
|
|
73
|
+
const input = tr.children[j].getElementsByClassName('el-table-column-edit')
|
|
74
|
+
if (input.length > 0) {
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
input[0].click()
|
|
77
|
+
e.stopPropagation()
|
|
78
|
+
}, 10)
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
/* empty */
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
},
|
|
89
|
+
unmounted: (el: HTMLElement) => {
|
|
90
|
+
el.removeEventListener('keydown', () => {})
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
export default vKeydown
|
|
@@ -1,78 +1,77 @@
|
|
|
1
|
-
import { ElMessage } from 'element-plus'
|
|
2
|
-
import SysDictCacheApi from '../api/SysDictCacheApi'
|
|
3
|
-
import type { ISysDictDataCacheVo } from '../interface/ISysDictDataCacheVo'
|
|
4
|
-
import { type dictDataMapVoType, dictStore } from '../stores/dictStore'
|
|
5
|
-
|
|
6
|
-
export default function useDictHooks(dictTypes: string[]) {
|
|
7
|
-
const dictStores = dictStore()
|
|
8
|
-
|
|
9
|
-
const getDict = async (dictTypes: string[]) => {
|
|
10
|
-
try {
|
|
11
|
-
//判断是否存在缓存数据,如果存在则不请求接口
|
|
12
|
-
const dictKeySet = new Set(Object.keys(dictStores.dictMap))
|
|
13
|
-
const uncachedDictTypes = dictTypes.filter((dictType) => !dictKeySet.has(dictType))
|
|
14
|
-
if (uncachedDictTypes.length) {
|
|
15
|
-
const data = await SysDictCacheApi.batchGetSysDictDataCacheVo(dictTypes)
|
|
16
|
-
dictStores.dictMap = { ...dictStores.dictMap, ...data }
|
|
17
|
-
// 获取默认值
|
|
18
|
-
Object.keys(data).forEach((item: string) => {
|
|
19
|
-
findDefaultValue(data[item], item)
|
|
20
|
-
const dataMap: dictDataMapVoType = {}
|
|
21
|
-
packageDictDataMap(dataMap, data[item])
|
|
22
|
-
dictStores.dictDataMap[item] = dataMap
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
} catch (error: any) {
|
|
26
|
-
ElMessage.error(error.msg || error.message)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const packageDictDataMap = async (map: dictDataMapVoType, list?: ISysDictDataCacheVo[]) => {
|
|
31
|
-
if (list && list.length) {
|
|
32
|
-
list.forEach((item: ISysDictDataCacheVo) => {
|
|
33
|
-
map[item.value] = { ...item, ...{ children: undefined } }
|
|
34
|
-
packageDictDataMap(map, item.children)
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const findDefaultValue = async (list: ISysDictDataCacheVo[], type: string) => {
|
|
40
|
-
const find = getDefaultValue(list)
|
|
41
|
-
if (find) {
|
|
42
|
-
dictStores.dictDefaultValueMap[type] = find
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const getDefaultValue = (list?: ISysDictDataCacheVo[]): ISysDictDataCacheVo | undefined => {
|
|
47
|
-
if (list && list.length) {
|
|
48
|
-
const find = list.find((item: ISysDictDataCacheVo) => item.isDefault === '1')
|
|
49
|
-
if (find) return find
|
|
50
|
-
for (const iSysDictDataCacheVo of list) {
|
|
51
|
-
const res = getDefaultValue(iSysDictDataCacheVo.children)
|
|
52
|
-
if (res) return res
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const getDictName = (value?: string, dictType?: string) => {
|
|
58
|
-
if (dictStores.dictDataMap[dictType!]) {
|
|
59
|
-
return dictStores.dictDataMap[dictType!][value!]?.label || value
|
|
60
|
-
}
|
|
61
|
-
return value
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const getDictData = (value: string, dictType: string) => {
|
|
65
|
-
return dictStores.dictDataMap[dictType!][value!]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getDict(dictTypes).then(() => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
1
|
+
import { ElMessage } from 'element-plus'
|
|
2
|
+
import SysDictCacheApi from '../api/SysDictCacheApi'
|
|
3
|
+
import type { ISysDictDataCacheVo } from '../interface/ISysDictDataCacheVo'
|
|
4
|
+
import { type dictDataMapVoType, dictStore } from '../stores/dictStore'
|
|
5
|
+
|
|
6
|
+
export default function useDictHooks(dictTypes: string[]) {
|
|
7
|
+
const dictStores = dictStore()
|
|
8
|
+
|
|
9
|
+
const getDict = async (dictTypes: string[]) => {
|
|
10
|
+
try {
|
|
11
|
+
//判断是否存在缓存数据,如果存在则不请求接口
|
|
12
|
+
const dictKeySet = new Set(Object.keys(dictStores.dictMap))
|
|
13
|
+
const uncachedDictTypes = dictTypes.filter((dictType) => !dictKeySet.has(dictType))
|
|
14
|
+
if (uncachedDictTypes.length) {
|
|
15
|
+
const data = await SysDictCacheApi.batchGetSysDictDataCacheVo(dictTypes)
|
|
16
|
+
dictStores.dictMap = { ...dictStores.dictMap, ...data }
|
|
17
|
+
// 获取默认值
|
|
18
|
+
Object.keys(data).forEach((item: string) => {
|
|
19
|
+
findDefaultValue(data[item], item)
|
|
20
|
+
const dataMap: dictDataMapVoType = {}
|
|
21
|
+
packageDictDataMap(dataMap, data[item])
|
|
22
|
+
dictStores.dictDataMap[item] = dataMap
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
} catch (error: any) {
|
|
26
|
+
ElMessage.error(error.msg || error.message)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const packageDictDataMap = async (map: dictDataMapVoType, list?: ISysDictDataCacheVo[]) => {
|
|
31
|
+
if (list && list.length) {
|
|
32
|
+
list.forEach((item: ISysDictDataCacheVo) => {
|
|
33
|
+
map[item.value] = { ...item, ...{ children: undefined } }
|
|
34
|
+
packageDictDataMap(map, item.children)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const findDefaultValue = async (list: ISysDictDataCacheVo[], type: string) => {
|
|
40
|
+
const find = getDefaultValue(list)
|
|
41
|
+
if (find) {
|
|
42
|
+
dictStores.dictDefaultValueMap[type] = find
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getDefaultValue = (list?: ISysDictDataCacheVo[]): ISysDictDataCacheVo | undefined => {
|
|
47
|
+
if (list && list.length) {
|
|
48
|
+
const find = list.find((item: ISysDictDataCacheVo) => item.isDefault === '1')
|
|
49
|
+
if (find) return find
|
|
50
|
+
for (const iSysDictDataCacheVo of list) {
|
|
51
|
+
const res = getDefaultValue(iSysDictDataCacheVo.children)
|
|
52
|
+
if (res) return res
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const getDictName = (value?: string, dictType?: string) => {
|
|
58
|
+
if (dictStores.dictDataMap[dictType!]) {
|
|
59
|
+
return dictStores.dictDataMap[dictType!][value!]?.label || value
|
|
60
|
+
}
|
|
61
|
+
return value
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const getDictData = (value: string, dictType: string) => {
|
|
65
|
+
return dictStores.dictDataMap[dictType!][value!]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getDict(dictTypes).then(() => {})
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
dictMap: dictStores.dictMap,
|
|
72
|
+
dictDefaultValueMap: dictStores.dictDefaultValueMap,
|
|
73
|
+
getDict,
|
|
74
|
+
getDictName,
|
|
75
|
+
getDictData,
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/hooks/useFileView.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { ref, onMounted, onUnmounted, createApp } from 'vue'
|
|
2
|
-
import FileView from '../components/upload/FileViewComponents.vue'
|
|
3
|
-
|
|
4
|
-
const useFileView = () => {
|
|
5
|
-
const ref_fileView = ref(null)
|
|
6
|
-
|
|
7
|
-
const fileView = (id: string) => {
|
|
8
|
-
if (ref_fileView.value) {
|
|
9
|
-
//@ts-ignore
|
|
10
|
-
ref_fileView.value?.viewFile(id)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
onMounted(() => {
|
|
15
|
-
const container = document.createElement('div')
|
|
16
|
-
document.body.appendChild(container)
|
|
17
|
-
//@ts-ignore
|
|
18
|
-
ref_fileView.value = createApp(FileView).mount(container)
|
|
19
|
-
onUnmounted(() => {
|
|
20
|
-
try {
|
|
21
|
-
//@ts-ignore
|
|
22
|
-
ref_fileView?.value.$destroy()
|
|
23
|
-
} catch {
|
|
24
|
-
/* empty */
|
|
25
|
-
}
|
|
26
|
-
document.body.removeChild(container)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
return {
|
|
30
|
-
fileView,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default useFileView
|
|
1
|
+
import { ref, onMounted, onUnmounted, createApp } from 'vue'
|
|
2
|
+
import FileView from '../components/upload/FileViewComponents.vue'
|
|
3
|
+
|
|
4
|
+
const useFileView = () => {
|
|
5
|
+
const ref_fileView = ref(null)
|
|
6
|
+
|
|
7
|
+
const fileView = (id: string) => {
|
|
8
|
+
if (ref_fileView.value) {
|
|
9
|
+
//@ts-ignore
|
|
10
|
+
ref_fileView.value?.viewFile(id)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
onMounted(() => {
|
|
15
|
+
const container = document.createElement('div')
|
|
16
|
+
document.body.appendChild(container)
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
ref_fileView.value = createApp(FileView).mount(container)
|
|
19
|
+
onUnmounted(() => {
|
|
20
|
+
try {
|
|
21
|
+
//@ts-ignore
|
|
22
|
+
ref_fileView?.value.$destroy()
|
|
23
|
+
} catch {
|
|
24
|
+
/* empty */
|
|
25
|
+
}
|
|
26
|
+
document.body.removeChild(container)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
return {
|
|
30
|
+
fileView,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default useFileView
|
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create by丁盼
|
|
3
|
-
* 说明: useMessageHooks
|
|
4
|
-
* 创建时间: 2024/9/3 下午5:27
|
|
5
|
-
* 修改时间: 2024/9/3 下午5:27
|
|
6
|
-
*/
|
|
7
|
-
//@ts-ignore
|
|
8
|
-
import io from 'socket.io-client'
|
|
9
|
-
import type { ISysMessageVo } from '../interface/Message'
|
|
10
|
-
import { messageStore } from '../stores/messageStore'
|
|
11
|
-
import { ElMessage, ElNotification } from 'element-plus'
|
|
12
|
-
import { useEventBus } from '@vueuse/core'
|
|
13
|
-
export default function useMessageHooks() {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
const connect = () => {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
window.socketIo.connect()
|
|
19
|
-
}
|
|
20
|
-
const bus = useEventBus<ISysMessageVo>('messageClick')
|
|
21
|
-
const message = messageStore()
|
|
22
|
-
const createSocket = () => {
|
|
23
|
-
const socket = io(import.meta.env.VITE_SOCKETIO_URL, {
|
|
24
|
-
query: {
|
|
25
|
-
token: sessionStorage.getItem('Authorization'),
|
|
26
|
-
refreshToken: sessionStorage.getItem('refreshToken'),
|
|
27
|
-
sessionId: sessionStorage.getItem('sessionId'),
|
|
28
|
-
},
|
|
29
|
-
path: '/socket.io/',
|
|
30
|
-
transports: ['websocket', 'polling'],
|
|
31
|
-
autoConnect: false,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const server_response = (res: any) => {}
|
|
35
|
-
socket.off('server_response', server_response)
|
|
36
|
-
socket.on('server_response', server_response)
|
|
37
|
-
const connect = () => {
|
|
38
|
-
message.clearSysMessage()
|
|
39
|
-
//连接成功 获取离线数据UserExpireMessageOnEvent
|
|
40
|
-
socket.emit('UserExpireMessageOnEvent')
|
|
41
|
-
}
|
|
42
|
-
socket.off('connect', connect)
|
|
43
|
-
socket.on('connect', connect)
|
|
44
|
-
socket.on('user_Offline', () => {
|
|
45
|
-
console.log('user offline')
|
|
46
|
-
ElMessage.warning('您已被强制下线,即将跳转至登录页,请重新登录')
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
window.location.href = '/'
|
|
49
|
-
}, 2000)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
const message_accept = (res: ISysMessageVo) => {
|
|
53
|
-
// if (res.params) {
|
|
54
|
-
// res.params = JSON.parse(res.params + '')
|
|
55
|
-
// }
|
|
56
|
-
let messageType = '通知'
|
|
57
|
-
if (res.messageType === 1) {
|
|
58
|
-
messageType = '消息'
|
|
59
|
-
} else if (res.messageType === 2) {
|
|
60
|
-
messageType = '待办'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const notif = ElNotification({
|
|
64
|
-
duration: 2000,
|
|
65
|
-
dangerouslyUseHTMLString: true,
|
|
66
|
-
onClick: () => {
|
|
67
|
-
bus.emit(res)
|
|
68
|
-
notif.close()
|
|
69
|
-
},
|
|
70
|
-
title: messageType,
|
|
71
|
-
message: res.title,
|
|
72
|
-
})
|
|
73
|
-
message.setSysMessage(res)
|
|
74
|
-
}
|
|
75
|
-
socket.off('message_accept', message_accept)
|
|
76
|
-
socket.on('message_accept', message_accept)
|
|
77
|
-
const expire_Message = (res: ISysMessageVo[]) => {
|
|
78
|
-
res.forEach((item) => {
|
|
79
|
-
message.setSysMessage(item)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
socket.off('expire_Message', expire_Message)
|
|
83
|
-
socket.on('expire_Message', expire_Message)
|
|
84
|
-
//@ts-ignore
|
|
85
|
-
window.socketIo = socket
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 接收方法注册
|
|
89
|
-
*/
|
|
90
|
-
const registerResponseEvent = (eventName: string, event: Function) => {
|
|
91
|
-
//@ts-ignore
|
|
92
|
-
window.socketIo.on(eventName, event)
|
|
93
|
-
}
|
|
94
|
-
const close = () => {
|
|
95
|
-
//@ts-ignore
|
|
96
|
-
window.socketIo.close()
|
|
97
|
-
message.clearSysMessage()
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 消息发送
|
|
101
|
-
* @param msg
|
|
102
|
-
*/
|
|
103
|
-
const messageSend = (msg: ISysMessageVo) => {
|
|
104
|
-
//@ts-ignore
|
|
105
|
-
window.socketIo.emit('messageSend', JSON.stringify(msg))
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 设置消息已读
|
|
109
|
-
* @constructor
|
|
110
|
-
*/
|
|
111
|
-
const setMessageRead = (msg: ISysMessageVo) => {
|
|
112
|
-
//@ts-ignore
|
|
113
|
-
window.socketIo.emit('setMessageRead', JSON.stringify(msg))
|
|
114
|
-
message.setSysMessageStatus(msg)
|
|
115
|
-
}
|
|
116
|
-
const setMessageReadAll = () => {
|
|
117
|
-
message.getMessageList.forEach((item) => {
|
|
118
|
-
//@ts-ignore
|
|
119
|
-
window.socketIo.emit('setMessageRead', JSON.stringify(item))
|
|
120
|
-
})
|
|
121
|
-
message.clearSysMessage()
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
close,
|
|
125
|
-
connect,
|
|
126
|
-
createSocket,
|
|
127
|
-
messageSend,
|
|
128
|
-
registerResponseEvent,
|
|
129
|
-
setMessageRead,
|
|
130
|
-
setMessageReadAll,
|
|
131
|
-
}
|
|
132
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Create by丁盼
|
|
3
|
+
* 说明: useMessageHooks
|
|
4
|
+
* 创建时间: 2024/9/3 下午5:27
|
|
5
|
+
* 修改时间: 2024/9/3 下午5:27
|
|
6
|
+
*/
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
import io from 'socket.io-client'
|
|
9
|
+
import type { ISysMessageVo } from '../interface/Message'
|
|
10
|
+
import { messageStore } from '../stores/messageStore'
|
|
11
|
+
import { ElMessage, ElNotification } from 'element-plus'
|
|
12
|
+
import { useEventBus } from '@vueuse/core'
|
|
13
|
+
export default function useMessageHooks() {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const connect = () => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
window.socketIo.connect()
|
|
19
|
+
}
|
|
20
|
+
const bus = useEventBus<ISysMessageVo>('messageClick')
|
|
21
|
+
const message = messageStore()
|
|
22
|
+
const createSocket = () => {
|
|
23
|
+
const socket = io(import.meta.env.VITE_SOCKETIO_URL, {
|
|
24
|
+
query: {
|
|
25
|
+
token: sessionStorage.getItem('Authorization'),
|
|
26
|
+
refreshToken: sessionStorage.getItem('refreshToken'),
|
|
27
|
+
sessionId: sessionStorage.getItem('sessionId'),
|
|
28
|
+
},
|
|
29
|
+
path: '/socket.io/',
|
|
30
|
+
transports: ['websocket', 'polling'],
|
|
31
|
+
autoConnect: false,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const server_response = (res: any) => {}
|
|
35
|
+
socket.off('server_response', server_response)
|
|
36
|
+
socket.on('server_response', server_response)
|
|
37
|
+
const connect = () => {
|
|
38
|
+
message.clearSysMessage()
|
|
39
|
+
//连接成功 获取离线数据UserExpireMessageOnEvent
|
|
40
|
+
socket.emit('UserExpireMessageOnEvent')
|
|
41
|
+
}
|
|
42
|
+
socket.off('connect', connect)
|
|
43
|
+
socket.on('connect', connect)
|
|
44
|
+
socket.on('user_Offline', () => {
|
|
45
|
+
console.log('user offline')
|
|
46
|
+
ElMessage.warning('您已被强制下线,即将跳转至登录页,请重新登录')
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
window.location.href = '/'
|
|
49
|
+
}, 2000)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const message_accept = (res: ISysMessageVo) => {
|
|
53
|
+
// if (res.params) {
|
|
54
|
+
// res.params = JSON.parse(res.params + '')
|
|
55
|
+
// }
|
|
56
|
+
let messageType = '通知'
|
|
57
|
+
if (res.messageType === 1) {
|
|
58
|
+
messageType = '消息'
|
|
59
|
+
} else if (res.messageType === 2) {
|
|
60
|
+
messageType = '待办'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const notif = ElNotification({
|
|
64
|
+
duration: 2000,
|
|
65
|
+
dangerouslyUseHTMLString: true,
|
|
66
|
+
onClick: () => {
|
|
67
|
+
bus.emit(res)
|
|
68
|
+
notif.close()
|
|
69
|
+
},
|
|
70
|
+
title: messageType,
|
|
71
|
+
message: res.title,
|
|
72
|
+
})
|
|
73
|
+
message.setSysMessage(res)
|
|
74
|
+
}
|
|
75
|
+
socket.off('message_accept', message_accept)
|
|
76
|
+
socket.on('message_accept', message_accept)
|
|
77
|
+
const expire_Message = (res: ISysMessageVo[]) => {
|
|
78
|
+
res.forEach((item) => {
|
|
79
|
+
message.setSysMessage(item)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
socket.off('expire_Message', expire_Message)
|
|
83
|
+
socket.on('expire_Message', expire_Message)
|
|
84
|
+
//@ts-ignore
|
|
85
|
+
window.socketIo = socket
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 接收方法注册
|
|
89
|
+
*/
|
|
90
|
+
const registerResponseEvent = (eventName: string, event: Function) => {
|
|
91
|
+
//@ts-ignore
|
|
92
|
+
window.socketIo.on(eventName, event)
|
|
93
|
+
}
|
|
94
|
+
const close = () => {
|
|
95
|
+
//@ts-ignore
|
|
96
|
+
window.socketIo.close()
|
|
97
|
+
message.clearSysMessage()
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 消息发送
|
|
101
|
+
* @param msg
|
|
102
|
+
*/
|
|
103
|
+
const messageSend = (msg: ISysMessageVo) => {
|
|
104
|
+
//@ts-ignore
|
|
105
|
+
window.socketIo.emit('messageSend', JSON.stringify(msg))
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 设置消息已读
|
|
109
|
+
* @constructor
|
|
110
|
+
*/
|
|
111
|
+
const setMessageRead = (msg: ISysMessageVo) => {
|
|
112
|
+
//@ts-ignore
|
|
113
|
+
window.socketIo.emit('setMessageRead', JSON.stringify(msg))
|
|
114
|
+
message.setSysMessageStatus(msg)
|
|
115
|
+
}
|
|
116
|
+
const setMessageReadAll = () => {
|
|
117
|
+
message.getMessageList.forEach((item) => {
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
window.socketIo.emit('setMessageRead', JSON.stringify(item))
|
|
120
|
+
})
|
|
121
|
+
message.clearSysMessage()
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
close,
|
|
125
|
+
connect,
|
|
126
|
+
createSocket,
|
|
127
|
+
messageSend,
|
|
128
|
+
registerResponseEvent,
|
|
129
|
+
setMessageRead,
|
|
130
|
+
setMessageReadAll,
|
|
131
|
+
}
|
|
132
|
+
}
|