@authing/vue-ui-components 3.1.1 → 3.1.6-rc.1

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 {
@@ -69,8 +62,8 @@ export default {
69
62
  data() {
70
63
  return {
71
64
  localVisible: false,
72
- $guard: null,
73
- localConfig: this.config
65
+ guardInstance: null,
66
+ guarConfig: {},
74
67
  };
75
68
  },
76
69
  watch: {
@@ -85,7 +78,7 @@ export default {
85
78
  localVisible: {
86
79
  handler(val) {
87
80
  if (val !== this.visible) {
88
- this.$emit("update:visible", val);
81
+ this.$emit("visible", val);
89
82
  }
90
83
 
91
84
  if (val) {
@@ -96,20 +89,21 @@ 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
-
107
- // this.config.autoRegister = format(this.autoRegister, this.config.autoRegister)
108
- // this.config.isSSO = format(this.isSSO, this.config.isSSO)
109
- // this.config.clickCloseable = format(this.clickCloseable, this.config.clickCloseable)
110
- // this.config.escCloseable = format(this.escCloseable, this.config.escCloseable)
111
-
112
- const guard = new NativeAuthingGuard(this.appId, this.localConfig, this.tenantId);
106
+ this.guardInstance = new NativeAuthingGuard(this.appId, this.mergeConfig, this.tenantId);
113
107
 
114
108
  const evts = Object.values(GuardEventsCamelToKebabMap);
115
109
  const kebabToCamelMap = Object.entries(GuardEventsCamelToKebabMap).reduce((acc, [camel, kebab]) => {
@@ -138,19 +132,18 @@ export default {
138
132
  });
139
133
  }, {});
140
134
 
141
- evts.forEach((evtName) => guard.on(evtName, listeners[evtName]));
135
+ evts.forEach((evtName) => this.guardInstance.on(evtName, listeners[evtName]));
142
136
 
143
137
  if (this.localVisible) {
144
- guard.show();
138
+ this.guardInstance.show();
145
139
  }
146
- this.$guard = guard;
147
140
  },
148
141
  methods: {
149
142
  show() {
150
- this.$guard.show();
143
+ this.guardInstance.show();
151
144
  },
152
145
  hide() {
153
- this.$guard.hide();
146
+ this.guardInstance.hide();
154
147
  },
155
148
  },
156
149
  };
@@ -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
+ }