@bdlite/domains 1.1.18
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/es/index.js +0 -0
- package/es/layout/channel.js +6 -0
- package/es/layout/constants.js +3 -0
- package/es/layout/index.js +13 -0
- package/es/portrait-selector.js +44 -0
- package/es/user/channel.js +7 -0
- package/es/user/constants.js +2 -0
- package/es/user/index.js +48 -0
- package/es/user/user-login.js +26 -0
- package/package.json +44 -0
package/es/index.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isObject } from '@bdlite/utils'
|
|
2
|
+
import { createObservableKit } from '@bdlite/observable/es/create-observable-kit'
|
|
3
|
+
import { CHANNEL_NAME, DEFAULT_LAYOUT_DATA } from './constants'
|
|
4
|
+
|
|
5
|
+
const { getData, subscribe, publish } = createObservableKit(DEFAULT_LAYOUT_DATA, null, { channelName: CHANNEL_NAME })
|
|
6
|
+
|
|
7
|
+
export const subscribeLayout = subscribe
|
|
8
|
+
|
|
9
|
+
export function publishLayout(data = {}) {
|
|
10
|
+
if (isObject(data)) {
|
|
11
|
+
publish({ ...getData(), ...data })
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isUndefined } from '@bdlite/utils'
|
|
2
|
+
|
|
3
|
+
import { createObservableKit, createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
|
|
4
|
+
|
|
5
|
+
const CHANNEL_NAME = 'portrait-selector'
|
|
6
|
+
const CURRENT_CHANNEL_NAME = `${CHANNEL_NAME}-current`
|
|
7
|
+
const OPERATE_CHANNEL_NAME = `${CHANNEL_NAME}-operate`
|
|
8
|
+
|
|
9
|
+
const { subscribe: subscribeCur } = createSubChannelKit({ channelName: CURRENT_CHANNEL_NAME }, { relay: 1 })
|
|
10
|
+
const { subscribe: subscribeOp } = createSubChannelKit({ channelName: OPERATE_CHANNEL_NAME })
|
|
11
|
+
let currentKit = null
|
|
12
|
+
|
|
13
|
+
export const subscribeCurrent = subscribeCur
|
|
14
|
+
export const subscribeOperate = subscribeOp
|
|
15
|
+
|
|
16
|
+
export function publishCurrent(data) {
|
|
17
|
+
if (!currentKit) {
|
|
18
|
+
currentKit = createObservableKit({}, null, { channelName: CURRENT_CHANNEL_NAME })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (isUndefined(data.id)) {
|
|
22
|
+
currentKit.observable.error(new Error('tableId is undefined.'))
|
|
23
|
+
} else {
|
|
24
|
+
currentKit.observable.next(data)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @function operateItem
|
|
31
|
+
* @param {object} item
|
|
32
|
+
*/
|
|
33
|
+
export function operateItem(item = {}) {
|
|
34
|
+
let { observable } = createObservableKit({}, null, { channelName: OPERATE_CHANNEL_NAME })
|
|
35
|
+
|
|
36
|
+
if (isUndefined(item.id)) {
|
|
37
|
+
observable.error(new Error('tableId is undefined.'))
|
|
38
|
+
} else {
|
|
39
|
+
observable.next(item)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
observable.close() // 如果按需创建,一定要调用close,因为事件会一直被监听
|
|
43
|
+
observable = null
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
|
|
2
|
+
import { CHANNEL_NAME } from './constants'
|
|
3
|
+
|
|
4
|
+
// 登录用户信息
|
|
5
|
+
const { subscribe } = createSubChannelKit({ channelName: CHANNEL_NAME }, { relay: 1 })
|
|
6
|
+
|
|
7
|
+
export const subscribeUser = subscribe
|
package/es/user/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createObservableKit } from '@bdlite/observable/es/create-observable-kit'
|
|
2
|
+
import { CHANNEL_NAME } from './constants'
|
|
3
|
+
|
|
4
|
+
// 登录用户信息
|
|
5
|
+
const { getData, subscribe, publish } = createObservableKit({ id: null, name: '', account: '', email: '' }, null, { channelName: CHANNEL_NAME })
|
|
6
|
+
const _userInfo = getData()
|
|
7
|
+
|
|
8
|
+
export const subscribeUser = subscribe
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @function showRules
|
|
12
|
+
* @param {?string} defaultName
|
|
13
|
+
* @param {?string} defaultEmail
|
|
14
|
+
* @returns {object} { showName, showEmail }
|
|
15
|
+
*/
|
|
16
|
+
export const getShowRules = userInfo => (defaultName = '', defaultEmail = '') => {
|
|
17
|
+
const { email, account, name, mobile, username } = userInfo
|
|
18
|
+
const showEmail = email || defaultEmail
|
|
19
|
+
const showName = name || mobile || username || account || defaultName
|
|
20
|
+
return { showName, showEmail }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @function storeUser
|
|
25
|
+
* @param {?object} user
|
|
26
|
+
*/
|
|
27
|
+
export function storeUser(user) {
|
|
28
|
+
if (!user) return
|
|
29
|
+
const { username = '', mobile = '', name = '', account = '', email = '', ...rest } = user
|
|
30
|
+
Object.assign(_userInfo, { username, mobile, name, account, email, ...rest })
|
|
31
|
+
publish({ ..._userInfo })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @function getUser
|
|
36
|
+
* @returns {object} userInfo
|
|
37
|
+
*/
|
|
38
|
+
export function getUser() {
|
|
39
|
+
return { ..._userInfo }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @function getUserId
|
|
44
|
+
* @returns {?number} id
|
|
45
|
+
*/
|
|
46
|
+
export function getUserId() {
|
|
47
|
+
return _userInfo.id
|
|
48
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createObservableKit, createSubChannelKit } from '@bdlite/observable/es/create-observable-kit'
|
|
2
|
+
import { LOGIN_CHANNEL_NAME } from './constants'
|
|
3
|
+
|
|
4
|
+
const _timestamp = new Date().getTime()
|
|
5
|
+
|
|
6
|
+
const obOptions = { relay: 0 }
|
|
7
|
+
const channelOptions = { useSession: false }
|
|
8
|
+
|
|
9
|
+
// 登录用户状态
|
|
10
|
+
const { publish } = createObservableKit({ timestamp: _timestamp, noLogin: true }, obOptions, { channelName: LOGIN_CHANNEL_NAME, channelOptions })
|
|
11
|
+
const { subscribe } = createSubChannelKit({ channelName: LOGIN_CHANNEL_NAME, channelOptions }, obOptions)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export const subscribeLoginStatus = subscribe
|
|
15
|
+
|
|
16
|
+
export function publishLoginStatus({ fromLoginPage, ...rest }) {
|
|
17
|
+
if (fromLoginPage) {
|
|
18
|
+
publish({ fromLoginPage, timestamp: _timestamp, ...rest })
|
|
19
|
+
} else {
|
|
20
|
+
publish(rest)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getTimestamp() {
|
|
25
|
+
return _timestamp
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bdlite/domains",
|
|
3
|
+
"version": "1.1.18",
|
|
4
|
+
"description": "A domains entity collection library driven by @bdlite/observable",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"DDD",
|
|
7
|
+
"domains",
|
|
8
|
+
"observable",
|
|
9
|
+
"Observable"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rollup -c",
|
|
13
|
+
"build:tsc": "tsc && rollup -c",
|
|
14
|
+
"start": "rollup -c -w"
|
|
15
|
+
},
|
|
16
|
+
"module": "es/index.js",
|
|
17
|
+
"main": "es/index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"es",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"authors": [
|
|
23
|
+
"Shirley Xie <yexinxie@163.com>"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@bdlite/observable": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@bdlite/observable": "^1.1.18"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-babel": "6.0.4",
|
|
34
|
+
"@rollup/plugin-eslint": "9.0.5",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
36
|
+
"@typescript-eslint/parser": "^5.60.1",
|
|
37
|
+
"eslint": "^8.43.0",
|
|
38
|
+
"husky": "^8.0.0",
|
|
39
|
+
"rollup": "4.9.5",
|
|
40
|
+
"rollup-plugin-typescript2": "^0.29.0",
|
|
41
|
+
"typescript": "^4.4.3"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "fa855142350d724b5a3cfabed0b9c10c3cae558d"
|
|
44
|
+
}
|