bi-element-ui 1.6.23 → 1.6.24-beta.2

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bi-element-ui",
3
- "version": "1.6.23",
3
+ "version": "1.6.24-beta.2",
4
4
  "private": false,
5
5
  "description": "基于 bi-eleme 编写的企业级 Vue 2 UI 组件库",
6
6
  "main": "lib/bi-element-ui-externals.common.js",
@@ -0,0 +1,110 @@
1
+ import Vue from 'vue'
2
+ import NoRole from './index.vue'
3
+
4
+ const APPLY_URL = {
5
+ production: 'https://zq.wozhangwan.com/createApproval',
6
+ default: 'https://zq.zwwlkj03.top/createApproval'
7
+ }
8
+
9
+ export const noRoleDefaults = {
10
+ title: '暂无访问权限',
11
+ // 默认不显示描述;-103 时由拦截器传入接口返回的 msg
12
+ description: '',
13
+ applyText: '申请访问权限',
14
+ applyUrl: '',
15
+ footerText: '有疑问?请联系小工具管理员',
16
+ contacts: [],
17
+ closable: true,
18
+ lockScroll: true
19
+ }
20
+
21
+ const NoRoleConstructor = Vue.extend(NoRole)
22
+
23
+ let currentConfig = { ...noRoleDefaults }
24
+ let instance = null
25
+ let bodyOverflow = ''
26
+ let scrollLocked = false
27
+
28
+ const normalizeContacts = (contacts) => {
29
+ const list = Array.isArray(contacts) ? contacts : typeof contacts === 'string' ? [contacts] : []
30
+ return [...new Set(list.filter(Boolean))]
31
+ }
32
+
33
+ const resolveApplyUrl = (applyUrl) => {
34
+ if (applyUrl) return applyUrl
35
+ const env = (typeof window !== 'undefined' && window.$BI && window.$BI.env) || ''
36
+ return env === 'prod' || env === 'production' ? APPLY_URL.production : APPLY_URL.default
37
+ }
38
+
39
+ const lockBodyScroll = () => {
40
+ bodyOverflow = document.body.style.overflow
41
+ document.body.style.overflow = 'hidden'
42
+ scrollLocked = true
43
+ }
44
+
45
+ const unlockBodyScroll = () => {
46
+ if (!scrollLocked) return
47
+ document.body.style.overflow = bodyOverflow
48
+ bodyOverflow = ''
49
+ scrollLocked = false
50
+ }
51
+
52
+ /**
53
+ * 修改无权限遮罩的默认文案与申请链接,影响后续所有 showNoRole 调用。
54
+ * 通常在 Vue.use(BiElementUI, { noRole: {...} }) 时下发。
55
+ *
56
+ * @param {{ title?: string, description?: string, applyText?: string, applyUrl?: string, footerText?: string, contacts?: string[]|string, closable?: boolean, lockScroll?: boolean }} config
57
+ */
58
+ export function setNoRoleConfig(config = {}) {
59
+ currentConfig = { ...currentConfig, ...config }
60
+ }
61
+
62
+ /**
63
+ * 显示「无角色权限」全屏遮罩。已显示时不重复挂载。
64
+ * description 为空时不渲染小字。
65
+ *
66
+ * @param {object} [config] 本次调用的临时覆盖项,不写入默认配置
67
+ * @returns {boolean} 是否新挂载(false 表示遮罩已存在)
68
+ */
69
+ export function showNoRole(config = {}) {
70
+ if (instance) return false
71
+ const merged = { ...currentConfig, ...config }
72
+
73
+ const vm = new NoRoleConstructor({
74
+ propsData: {
75
+ title: merged.title,
76
+ description: typeof merged.description === 'string' ? merged.description : '',
77
+ applyText: merged.applyText,
78
+ applyUrl: resolveApplyUrl(merged.applyUrl),
79
+ footerText: merged.footerText,
80
+ contacts: normalizeContacts(merged.contacts),
81
+ closable: merged.closable
82
+ }
83
+ })
84
+ vm.$on('close', closeNoRole)
85
+ vm.$mount()
86
+ document.body.appendChild(vm.$el)
87
+
88
+ instance = vm
89
+
90
+ if (merged.lockScroll) lockBodyScroll()
91
+
92
+ return true
93
+ }
94
+
95
+ /**
96
+ * 关闭并销毁无权限遮罩,同时恢复 body 滚动。遮罩未显示时为无操作。
97
+ */
98
+ export function closeNoRole() {
99
+ if (!instance) return
100
+ const vm = instance
101
+ instance = null
102
+
103
+ vm.$off('close', closeNoRole)
104
+ vm.$destroy()
105
+ if (vm.$el && vm.$el.parentNode) {
106
+ vm.$el.parentNode.removeChild(vm.$el)
107
+ }
108
+
109
+ unlockBodyScroll()
110
+ }
@@ -0,0 +1,242 @@
1
+ <template>
2
+ <div class="bi-no-role">
3
+ <div class="bi-no-role__card">
4
+ <button
5
+ v-if="closable"
6
+ type="button"
7
+ class="bi-no-role__close"
8
+ aria-label="关闭"
9
+ @click="$emit('close')"
10
+ >
11
+ ×
12
+ </button>
13
+
14
+ <h2 class="bi-no-role__title">{{ title }}</h2>
15
+ <p
16
+ v-if="description"
17
+ class="bi-no-role__desc"
18
+ >{{ description }}</p>
19
+
20
+ <button
21
+ type="button"
22
+ class="bi-no-role__btn"
23
+ @click="goApply"
24
+ >
25
+ {{ applyText }}
26
+ <span class="bi-no-role__arrow">→</span>
27
+ </button>
28
+
29
+ <template v-if="contacts.length">
30
+ <div class="bi-no-role__divider"></div>
31
+ <div class="bi-no-role__footer">
32
+ <span class="bi-no-role__footer-text">{{ footerText }}</span>
33
+ <span
34
+ v-for="item in contacts"
35
+ :key="item"
36
+ class="bi-no-role__tag"
37
+ >{{ item }}</span>
38
+ </div>
39
+ </template>
40
+ </div>
41
+ </div>
42
+ </template>
43
+
44
+ <script>
45
+ export default {
46
+ name: 'BiNoRole',
47
+ props: {
48
+ title: {
49
+ type: String,
50
+ default: ''
51
+ },
52
+ description: {
53
+ type: String,
54
+ default: ''
55
+ },
56
+ applyText: {
57
+ type: String,
58
+ default: ''
59
+ },
60
+ applyUrl: {
61
+ type: String,
62
+ default: ''
63
+ },
64
+ footerText: {
65
+ type: String,
66
+ default: ''
67
+ },
68
+ contacts: {
69
+ type: Array,
70
+ default: () => []
71
+ },
72
+ closable: {
73
+ type: Boolean,
74
+ default: true
75
+ }
76
+ },
77
+ methods: {
78
+ goApply() {
79
+ if (!this.applyUrl) return
80
+ window.open(this.applyUrl, '_blank', 'noopener')
81
+ }
82
+ }
83
+ }
84
+ </script>
85
+
86
+ <style lang="scss" scoped>
87
+ .bi-no-role {
88
+ position: fixed;
89
+ top: 0;
90
+ right: 0;
91
+ bottom: 0;
92
+ left: 0;
93
+ z-index: 3000;
94
+ display: flex;
95
+ align-items: center;
96
+ justify-content: center;
97
+ overflow: auto;
98
+ padding: 24px;
99
+ box-sizing: border-box;
100
+ background: rgba(0, 0, 0, 0.5);
101
+ animation: bi-no-role-fade-in 0.2s ease;
102
+ }
103
+
104
+ @keyframes bi-no-role-fade-in {
105
+ from {
106
+ opacity: 0;
107
+ }
108
+ to {
109
+ opacity: 1;
110
+ }
111
+ }
112
+
113
+ .bi-no-role__card {
114
+ position: relative;
115
+ width: 640px;
116
+ max-width: 100%;
117
+ padding: 48px 56px 32px;
118
+ box-sizing: border-box;
119
+ background: #fff;
120
+ border: 1px solid #e5e6eb;
121
+ border-radius: 8px;
122
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
123
+ text-align: center;
124
+ }
125
+
126
+ .bi-no-role__close {
127
+ position: absolute;
128
+ top: 12px;
129
+ right: 12px;
130
+ width: 32px;
131
+ height: 32px;
132
+ margin: 0;
133
+ padding: 0;
134
+ border: none;
135
+ border-radius: 4px;
136
+ background: transparent;
137
+ color: #86909c;
138
+ font-size: 22px;
139
+ line-height: 1;
140
+ cursor: pointer;
141
+ outline: none;
142
+ transition: color 0.2s ease, background-color 0.2s ease;
143
+
144
+ &:hover {
145
+ background: #f2f3f5;
146
+ color: #1d2129;
147
+ }
148
+ }
149
+
150
+ .bi-no-role__title {
151
+ margin: 0 0 16px;
152
+ font-size: 28px;
153
+ font-weight: 700;
154
+ line-height: 1.3;
155
+ color: #1d2129;
156
+ }
157
+
158
+ .bi-no-role__desc {
159
+ margin: 0 0 36px;
160
+ font-size: 16px;
161
+ line-height: 1.6;
162
+ color: #4e5969;
163
+ }
164
+
165
+ .bi-no-role__btn {
166
+ display: inline-flex;
167
+ align-items: center;
168
+ justify-content: center;
169
+ gap: 8px;
170
+ width: 100%;
171
+ height: 52px;
172
+ margin: 0;
173
+ padding: 0 24px;
174
+ border: none;
175
+ border-radius: 6px;
176
+ background: #00b578;
177
+ color: #fff;
178
+ font-size: 18px;
179
+ font-weight: 600;
180
+ line-height: 1;
181
+ cursor: pointer;
182
+ outline: none;
183
+ transition: background-color 0.2s ease;
184
+
185
+ &:hover {
186
+ background: #00a06b;
187
+ }
188
+
189
+ &:active {
190
+ background: #008f60;
191
+ }
192
+ }
193
+
194
+ .bi-no-role__arrow {
195
+ font-size: 18px;
196
+ font-weight: 400;
197
+ line-height: 1;
198
+ }
199
+
200
+ .bi-no-role__divider {
201
+ height: 1px;
202
+ margin: 28px 0 24px;
203
+ background: #e5e6eb;
204
+ }
205
+
206
+ .bi-no-role__footer {
207
+ display: flex;
208
+ align-items: center;
209
+ justify-content: center;
210
+ flex-wrap: wrap;
211
+ gap: 10px;
212
+ }
213
+
214
+ .bi-no-role__footer-text {
215
+ font-size: 14px;
216
+ color: #86909c;
217
+ }
218
+
219
+ .bi-no-role__tag {
220
+ display: inline-flex;
221
+ align-items: center;
222
+ height: 32px;
223
+ padding: 0 14px;
224
+ border: 1px solid #e5e6eb;
225
+ border-radius: 4px;
226
+ background: #f7f8fa;
227
+ font-size: 14px;
228
+ font-weight: 600;
229
+ color: #1d2129;
230
+ line-height: 1;
231
+ }
232
+
233
+ @media (max-width: 768px) {
234
+ .bi-no-role__card {
235
+ padding: 40px 24px 24px;
236
+ }
237
+
238
+ .bi-no-role__title {
239
+ font-size: 22px;
240
+ }
241
+ }
242
+ </style>
@@ -1,9 +1,22 @@
1
1
  import { doubleCheckVerification } from '../Verification'
2
+ import { showNoRole } from '../NoRole/api'
3
+
4
+ // -103 无角色权限:宿主传入回调则交给宿主接管,否则弹出组件库内置的全屏遮罩。
5
+ // 小字展示接口返回的 msg。
6
+ const handleNoRole = (customCallback, res) => {
7
+ if (typeof customCallback === 'function') {
8
+ customCallback()
9
+ return
10
+ }
11
+ const msg = res && typeof res.msg === 'string' ? res.msg : ''
12
+ showNoRole(msg ? { description: msg } : {})
13
+ }
2
14
 
3
15
  class ResponseInterceptor {
4
16
  constructor() {
5
17
  this.statusCodeHandlers = {
6
- 202: doubleCheckVerification
18
+ 202: doubleCheckVerification,
19
+ [-103]: handleNoRole
7
20
  // 未来可以轻松添加新的状态码处理
8
21
  // 203: this.handleSmsVerification,
9
22
  // 204: this.handleBiometricVerification,
@@ -21,10 +34,10 @@ class ResponseInterceptor {
21
34
  const customCallback = customCallbacks[res.status_code] || this.customCallbacks[res.status_code]
22
35
  if (customCallback && typeof customCallback === 'function') {
23
36
  // 使用自定义回调,将回调传给原始处理器
24
- handler(customCallback)
37
+ handler(customCallback, res)
25
38
  } else {
26
39
  // 使用默认处理器,不传回调
27
- handler()
40
+ handler(undefined, res)
28
41
  }
29
42
  }
30
43
  } catch (error) {
package/packages/index.js CHANGED
@@ -40,6 +40,7 @@ import BiTableSticky from './TableSticky/index'
40
40
  import { doubleCheckVerification } from './Verification/index.js'
41
41
  import ResponseInterceptor from './ResponseInterceptor'
42
42
  import { openNoticeDialog } from './NoticeCenter/noticeDialogApi'
43
+ import { showNoRole, closeNoRole, setNoRoleConfig } from './NoRole/api'
43
44
  // import BiVerification from './Verification/index.js'
44
45
 
45
46
  // 组件列表
@@ -121,6 +122,8 @@ const install = function (Vue, config = {}) {
121
122
  system: config.system,
122
123
  request: config.request,
123
124
  openNoticeDialog,
125
+ showNoRole,
126
+ closeNoRole,
124
127
  needIcon: false,
125
128
  iconInit: false,
126
129
  iconList: {},
@@ -132,6 +135,11 @@ const install = function (Vue, config = {}) {
132
135
  Vue.prototype.$BI.needIcon = true
133
136
  }
134
137
 
138
+ // 无角色权限(-103)遮罩的文案与申请链接,可在此覆盖默认值
139
+ if (config && config.noRole) {
140
+ setNoRoleConfig(config.noRole)
141
+ }
142
+
135
143
  // Vue.prototype.$BiEnv = config.env || 'production'
136
144
  Vue.prototype.$AccessReport = new AccessReport({ system: config.system, env: config.env || 'production' })
137
145
  window.$BI = Vue.prototype.$BI
@@ -227,9 +235,12 @@ export default {
227
235
  doubleCheckVerification: doubleCheckVerification,
228
236
  handleResponse: ResponseInterceptor.handleResponse.bind(ResponseInterceptor),
229
237
  openNoticeDialog,
238
+ showNoRole,
239
+ closeNoRole,
240
+ setNoRoleConfig,
230
241
  version: pkg.version
231
242
  }
232
243
 
233
244
  // 命名导出
234
- export { doubleCheckVerification, getComponentsKeys, openNoticeDialog }
245
+ export { doubleCheckVerification, getComponentsKeys, openNoticeDialog, showNoRole, closeNoRole, setNoRoleConfig }
235
246
  export const handleResponse = ResponseInterceptor.handleResponse.bind(ResponseInterceptor)