@authing/vue-ui-components 3.1.1 → 3.1.6

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.
@@ -0,0 +1,8 @@
1
+ import AuthingGuard from './src/index.vue'
2
+ import '@authing/native-js-ui-components/lib/index.min.css'
3
+
4
+ AuthingGuard.install = (app) => {
5
+ app.component(AuthingGuard.name, AuthingGuard)
6
+ }
7
+
8
+ export default AuthingGuard
@@ -1,19 +1,12 @@
1
1
  <template>
2
- <div id="authing_guard_container"></div>
2
+ <div id="authing_guard_container" />
3
3
  </template>
4
4
 
5
5
  <script>
6
- import {
7
- AuthingGuard as NativeAuthingGuard,
8
- GuardEventsCamelToKebabMap,
9
- } from "@authing/native-js-ui-components";
6
+ import { AuthingGuard as NativeAuthingGuard, GuardEventsCamelToKebabMap } from "@authing/native-js-ui-components";
10
7
 
11
8
  import "@authing/native-js-ui-components/lib/index.min.css";
12
9
 
13
- const format = (a, b) => {
14
- return !a || a === "false" ? b : true;
15
- };
16
-
17
10
  const callbackEvent = ["before-login", "before-register"];
18
11
 
19
12
  export default {
@@ -70,7 +63,7 @@ export default {
70
63
  return {
71
64
  localVisible: false,
72
65
  $guard: null,
73
- localConfig: this.config
66
+ guarConfig: {},
74
67
  };
75
68
  },
76
69
  watch: {
@@ -96,20 +89,33 @@ export default {
96
89
  },
97
90
  },
98
91
  },
92
+ computed: {
93
+ mergeConfig: function () {
94
+ return {
95
+ ...this.config,
96
+ appId: this.appId,
97
+ mode: this.mode ?? this.config?.mode,
98
+ autoRegister: this.autoRegister ?? this.config?.autoRegister,
99
+ isSSO: this.isSSO ?? this.config?.isSSO,
100
+ clickCloseable: this.clickCloseable ?? this.config?.clickCloseable,
101
+ escCloseable: this.escCloseable ?? this.config?.escCloseable,
102
+ };
103
+ },
104
+ },
99
105
  mounted() {
100
- this.localConfig = this.localConfig || {};
101
- this.localConfig.mode = this.mode ? this.mode : this.localConfig.mode;
102
- this.localConfig.autoRegister = this.autoRegister ? this.autoRegister : this.localConfig.autoRegister;
103
- this.localConfig.isSSO = this.isSSO ? this.isSSO : this.localConfig.isSSO;
104
- this.localConfig.clickCloseable = this.clickCloseable ? this.clickCloseable : this.localConfig.clickCloseable;
105
- this.localConfig.escCloseable = this.escCloseable ? this.escCloseable : this.localConfig.escCloseable;
106
+ // this.guarConfig = this.config || {};
107
+ // this.guarConfig.mode = this.mode ? this.mode : this.config.mode;
108
+ // this.guarConfig.autoRegister = this.autoRegister ? this.autoRegister : this.config.autoRegister;
109
+ // this.guarConfig.isSSO = this.isSSO ? this.isSSO : this.config.isSSO;
110
+ // this.guarConfig.clickCloseable = this.clickCloseable ? this.clickCloseable : this.config.clickCloseable;
111
+ // this.guarConfig.escCloseable = this.escCloseable ? this.escCloseable : this.config.escCloseable;
106
112
 
107
113
  // this.config.autoRegister = format(this.autoRegister, this.config.autoRegister)
108
114
  // this.config.isSSO = format(this.isSSO, this.config.isSSO)
109
115
  // this.config.clickCloseable = format(this.clickCloseable, this.config.clickCloseable)
110
116
  // this.config.escCloseable = format(this.escCloseable, this.config.escCloseable)
111
117
 
112
- const guard = new NativeAuthingGuard(this.appId, this.localConfig, this.tenantId);
118
+ const guard = new NativeAuthingGuard(this.appId, this.mergeConfig, this.tenantId);
113
119
 
114
120
  const evts = Object.values(GuardEventsCamelToKebabMap);
115
121
  const kebabToCamelMap = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [camel, kebab]) => {
@@ -0,0 +1,8 @@
1
+ import Guard from './src/index.vue'
2
+ import '@authing/native-js-ui-components/lib/index.min.css'
3
+
4
+ Guard.install = (app) => {
5
+ app.component(Guard.name, Guard)
6
+ }
7
+
8
+ export default Guard
@@ -0,0 +1,156 @@
1
+ <template>
2
+ <div id="authing_guard_container" />
3
+ </template>
4
+
5
+ <script>
6
+ import {
7
+ getAuthClient,
8
+ initAuthClient,
9
+ GuardEventsCamelToKebabMap,
10
+ GuardMode,
11
+ GuardScenes,
12
+ LoginMethods,
13
+ RegisterMethods,
14
+ } from "@authing/native-js-ui-components";
15
+ import "@authing/native-js-ui-components/lib/index.min.css";
16
+ import { Guard as NativeGuard } from "@authing/native-js-ui-components/lib/index.min.js";
17
+
18
+ export { getAuthClient, initAuthClient, GuardMode, GuardScenes, LoginMethods, RegisterMethods };
19
+
20
+ const callbackEvent = ["before-login", "before-register"];
21
+
22
+ export default {
23
+ name: "Guard",
24
+ props: {
25
+ appId: {
26
+ type: String,
27
+ required: true,
28
+ },
29
+ config: {
30
+ type: Object,
31
+ required: false,
32
+ },
33
+ visible: {
34
+ type: Boolean,
35
+ default: false,
36
+ },
37
+ mode: {
38
+ type: String,
39
+ required: false, // normal(全屏) modal(弹窗)
40
+ },
41
+ autoRegister: {
42
+ type: Boolean,
43
+ required: false,
44
+ },
45
+ isSSO: {
46
+ type: Boolean,
47
+ required: false,
48
+ },
49
+ clickCloseable: {
50
+ type: Boolean,
51
+ default: true,
52
+ required: false,
53
+ },
54
+ escCloseable: {
55
+ type: Boolean,
56
+ default: true,
57
+ required: false,
58
+ },
59
+ onBeforeLogin: {
60
+ type: Function,
61
+ required: false,
62
+ },
63
+ onBeforeRegister: {
64
+ type: Function,
65
+ required: false,
66
+ },
67
+ },
68
+ data() {
69
+ return {
70
+ localVisible: false,
71
+ guardInstance: null,
72
+ guarConfig: {},
73
+ };
74
+ },
75
+ watch: {
76
+ visible: {
77
+ immediate: true,
78
+ handler(val) {
79
+ if (val !== this.localVisible) {
80
+ this.localVisible = val;
81
+ }
82
+ },
83
+ },
84
+ localVisible: {
85
+ handler(val) {
86
+ if (val !== this.visible) {
87
+ this.$emit("visible", val);
88
+ }
89
+
90
+ if (val) {
91
+ this.show();
92
+ } else {
93
+ this.hide();
94
+ }
95
+ },
96
+ },
97
+ },
98
+ computed: {
99
+ mergeConfig: function () {
100
+ return {
101
+ ...this.config,
102
+ appId: this.appId,
103
+ mode: this.mode ?? this.config?.mode,
104
+ autoRegister: this.autoRegister ?? this.config?.autoRegister,
105
+ isSSO: this.isSSO ?? this.config?.isSSO,
106
+ clickCloseable: this.clickCloseable ?? this.config?.clickCloseable,
107
+ escCloseable: this.escCloseable ?? this.config?.escCloseable,
108
+ };
109
+ },
110
+ },
111
+ mounted() {
112
+ this.guardInstance = new NativeGuard(this.appId, this.mergeConfig);
113
+
114
+ const evts = Object.values(GuardEventsCamelToKebabMap);
115
+ const kebabToCamelMap = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [camel, kebab]) => {
116
+ return Object.assign({}, acc, {
117
+ [kebab]: camel,
118
+ });
119
+ }, {});
120
+
121
+ const listeners = evts.reduce((acc, evtName) => {
122
+ return Object.assign({}, acc, {
123
+ [evtName]: (...rest) => {
124
+ if (evtName === "close") {
125
+ this.localVisible = false;
126
+ }
127
+ if (!callbackEvent.includes(evtName)) {
128
+ this.$emit(evtName, ...rest);
129
+ } else {
130
+ const camelEvtName = kebabToCamelMap[evtName];
131
+
132
+ if (this[camelEvtName]) {
133
+ return this[camelEvtName](...rest);
134
+ }
135
+ return true;
136
+ }
137
+ },
138
+ });
139
+ }, {});
140
+
141
+ evts.forEach((evtName) => this.guardInstance.on(evtName, listeners[evtName]));
142
+
143
+ if (this.localVisible) {
144
+ this.guardInstance.show();
145
+ }
146
+ },
147
+ methods: {
148
+ show() {
149
+ this.guardInstance.show();
150
+ },
151
+ hide() {
152
+ this.guardInstance.hide();
153
+ },
154
+ },
155
+ };
156
+ </script>
@@ -0,0 +1,25 @@
1
+ import AuthingGuard from './AuthingGuard'
2
+ import Guard from './Guard'
3
+ import '@authing/native-js-ui-components/lib/index.min.css'
4
+
5
+ const components = [
6
+ AuthingGuard,
7
+ Guard
8
+ ]
9
+ // 全局注册
10
+ const install = (app) => {
11
+ components.forEach(component => {
12
+ app.component(component.name, component)
13
+ })
14
+ }
15
+
16
+ // 局部注册
17
+ export {
18
+ install,
19
+ Guard,
20
+ AuthingGuard
21
+ }
22
+
23
+ export default {
24
+ install
25
+ }