vue-alive-check 1.0.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.
package/jsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "esnext",
5
+ "baseUrl": "./",
6
+ "moduleResolution": "node",
7
+ "paths": {
8
+ "@/*": [
9
+ "src/*"
10
+ ]
11
+ },
12
+ "lib": [
13
+ "esnext",
14
+ "dom",
15
+ "dom.iterable",
16
+ "scripthost"
17
+ ]
18
+ }
19
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "vue-alive-check",
3
+ "version": "1.0.6",
4
+ "private": false,
5
+ "description": "活体检测 + 人脸登陆,人脸注册,扫码登陆",
6
+ "main": "dist/vue-alive-check.common.js",
7
+ "author": "175916735@qq.com",
8
+ "license": "ISC",
9
+ "keywords": [
10
+ "vue-face-login",
11
+ "vue-alive-check"
12
+ ],
13
+ "scripts": {
14
+ "dev": "vue-cli-service serve --mode dev",
15
+ "serve": "vue-cli-service serve",
16
+ "build": "vue-cli-service build",
17
+ "lint": "vue-cli-service lint",
18
+ "package": "vue-cli-service build --target lib --name vue-alive-check --dest dist ./packages/index.js"
19
+ },
20
+ "dependencies": {
21
+ "axios": "^0.27.2",
22
+ "core-js": "^3.8.3",
23
+ "element-ui": "^2.15.14",
24
+ "vue": "^2.6.14",
25
+ "vue-qr": "^4.0.9",
26
+ "vue-router": "^3.4.9"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/core": "^7.12.16",
30
+ "@babel/eslint-parser": "^7.12.16",
31
+ "@vue/cli-plugin-babel": "~5.0.0",
32
+ "@vue/cli-plugin-eslint": "~5.0.0",
33
+ "@vue/cli-service": "~5.0.0",
34
+ "eslint": "^7.32.0",
35
+ "eslint-plugin-vue": "^8.0.3",
36
+ "sass": "1.32.13",
37
+ "sass-loader": "10.2.0",
38
+ "vue-template-compiler": "^2.6.14"
39
+ },
40
+ "engines": {
41
+ "node": ">= 10.13.0",
42
+ "npm": ">= 5.0.0"
43
+ },
44
+ "browserslist": [
45
+ "> 1%",
46
+ "last 2 versions"
47
+ ]
48
+ }
Binary file
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html lang="">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
+ <link rel="icon" href="<%= BASE_URL %>favicon.ico">
8
+ <title><%= htmlWebpackPlugin.options.title %></title>
9
+ </head>
10
+ <body>
11
+ <noscript>
12
+ <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
13
+ </noscript>
14
+ <div id="app"></div>
15
+ <!-- built files will be auto injected -->
16
+ </body>
17
+ </html>
package/src/App.vue ADDED
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <div id="app">
3
+ <router-view />
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ name: 'App',
10
+ components: {
11
+ },
12
+ data() {
13
+ return {
14
+ page: undefined,
15
+ };
16
+ },
17
+ mounted(){
18
+
19
+ },
20
+ methods:{
21
+ goPage(page){
22
+ }
23
+ }
24
+
25
+ }
26
+
27
+ </script>
28
+
29
+ <style>
30
+ #app {
31
+ font-size: 14px;
32
+ margin: 0px auto;
33
+ text-align: initial !important;
34
+ }
35
+ body{
36
+ margin: 0px !important;
37
+ }
38
+ </style>
@@ -0,0 +1,20 @@
1
+ import request from '@/utils/request'
2
+
3
+
4
+ export function uploadShard(data) {
5
+ return request({
6
+ baseURL: '/face-api/',
7
+ url: '/uploadShard',
8
+ method: 'post',
9
+ data: data
10
+ })
11
+ }
12
+
13
+ export function aliveDetect(data) {
14
+ return request({
15
+ baseURL: '/face-api/',
16
+ url: '/aliveDetect',
17
+ method: 'post',
18
+ data: data
19
+ })
20
+ }
@@ -0,0 +1,33 @@
1
+ import request from '@/utils/request'
2
+
3
+ // 人脸识别登陆
4
+ export function faceRegister(data) {
5
+ return request({
6
+ baseURL: '/face-api/',
7
+ url: '/face-register',
8
+ method: 'post',
9
+ data: data
10
+ })
11
+ }
12
+
13
+ // 人脸识别登陆
14
+ export function faceLogin(data) {
15
+ return request({
16
+ baseURL: '/face-api/',
17
+ url: '/face-login',
18
+ method: 'post',
19
+ data: data
20
+ })
21
+ }
22
+
23
+
24
+ // 人脸识别登陆
25
+ export function getLoginResult(data) {
26
+ return request({
27
+ baseURL: '/face-api/',
28
+ url: '/face-login-result',
29
+ method: 'post',
30
+ data: data
31
+ })
32
+ }
33
+
@@ -0,0 +1,31 @@
1
+ /**
2
+ * I think element-ui's default theme color is too light for long-term use.
3
+ * So I modified the default color and you can modify it to your liking.
4
+ **/
5
+
6
+ /* theme color */
7
+ $--color-primary: #1890ff;
8
+ $--color-success: #13ce66;
9
+ $--color-warning: #ffba00;
10
+ $--color-danger: #ff4949;
11
+ // $--color-info: #1E1E1E;
12
+
13
+ $--button-font-weight: 400;
14
+
15
+ // $--color-text-regular: #1f2d3d;
16
+
17
+ $--border-color-light: #dfe4ed;
18
+ $--border-color-lighter: #e6ebf5;
19
+
20
+ $--table-border: 1px solid#dfe6ec;
21
+
22
+ /* icon font path, required */
23
+ $--font-path: '~element-ui/lib/theme-chalk/fonts';
24
+
25
+ @import "~element-ui/packages/theme-chalk/src/index";
26
+
27
+ // the :export directive is the magic sauce for webpack
28
+ // https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass
29
+ :export {
30
+ theme: $--color-primary;
31
+ }
Binary file
Binary file
Binary file
package/src/index.vue ADDED
@@ -0,0 +1,58 @@
1
+ <template>
2
+ <div style="margin:10px;">
3
+ <div v-if="hasLogin()">
4
+ <div>{{auth.getUsername()}},登陆成功</div>
5
+ <el-link type="primary" :underline="false" @click="logout">退出</el-link>
6
+ </div>
7
+ <div v-else>
8
+ <div style="">
9
+ <el-link type="primary" :underline="false" href="./login">人脸登陆</el-link>
10
+ <span class="padding-10"></span>
11
+ <el-link type="primary" :underline="false" href="./register">注册人脸</el-link>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ </template>
16
+
17
+ <script>
18
+ import * as auth from '@/utils/auth'
19
+
20
+ export default {
21
+ name: 'Index',
22
+ components: {
23
+ },
24
+ data() {
25
+ return {
26
+ auth: auth,
27
+ page: undefined,
28
+ loginUrl: window.location.href+"login",
29
+ registerUrl: window.location.href+"register",
30
+ activeTab: 'login'
31
+ };
32
+ },
33
+ mounted(){
34
+ console.log(this.loginUrl)
35
+ },
36
+ methods:{
37
+ hasLogin(){
38
+ return auth.getAccessToken() ? true : false;
39
+ },
40
+ logout(){
41
+ auth.removeToken()
42
+ auth.removeTenantId();
43
+ this.$router.push({name:"Login"})
44
+ },
45
+ goPage(page){
46
+ this.$router.push({path:page});
47
+ }
48
+ }
49
+
50
+ }
51
+
52
+ </script>
53
+
54
+ <style>
55
+ #app {
56
+ font-size: 14px;
57
+ }
58
+ </style>
package/src/main.js ADDED
@@ -0,0 +1,26 @@
1
+ import Vue from 'vue'
2
+ import App from './App.vue'
3
+ import Element from 'element-ui'
4
+ import './assets/element-variables.scss'
5
+
6
+ import FaceRegister from "vue-alive-check"
7
+ import AliveCheckLogin from "vue-alive-check"
8
+ import "vue-alive-check/dist/vue-alive-check.css"
9
+ Vue.use(AliveCheckLogin);
10
+ Vue.use(FaceRegister);
11
+
12
+ import router from './router'
13
+
14
+ Element.Dialog.props.closeOnClickModal.default = false
15
+ Vue.use(Element, {
16
+ size: localStorage.getItem("size") || "medium",
17
+ });
18
+
19
+ Vue.config.productionTip = false
20
+
21
+ var app = undefined
22
+ app = new Vue({
23
+ el: '#app',
24
+ router,
25
+ render: h => h(App)
26
+ })
@@ -0,0 +1,58 @@
1
+ import Vue from 'vue'
2
+ import Router from 'vue-router'
3
+
4
+ Vue.use(Router)
5
+
6
+ // 公共路由
7
+ export const constantRoutes = [
8
+ {
9
+ path: '/',
10
+ name: 'Index',
11
+ component: (resolve) => require(['@/index'], resolve),
12
+ meta: {
13
+ title: "首页"
14
+ },
15
+ hidden: false
16
+ },
17
+ {
18
+ path: '/login',
19
+ name: 'Login',
20
+ component: (resolve) => require(['@/views/login'], resolve),
21
+ meta: {
22
+ title: "人脸登录"
23
+ },
24
+ hidden: false
25
+ },
26
+ {
27
+ path: '/register',
28
+ name: 'Register',
29
+ component: (resolve) => require(['@/views/register'], resolve),
30
+ meta: {
31
+ title: "人脸注册"
32
+ },
33
+ hidden: false
34
+ },
35
+ {
36
+ path: '/policy',
37
+ name: 'Rolicy',
38
+ component: (resolve) => require(['@/views/policy'], resolve),
39
+ meta: {
40
+ title: "隐私协议"
41
+ },
42
+ hidden: false
43
+ },
44
+ ]
45
+
46
+ // 防止连续点击多次路由报错
47
+ let routerPush = Router.prototype.push;
48
+ Router.prototype.push = function push(location) {
49
+ return routerPush.call(this, location).catch(err => err)
50
+ }
51
+
52
+ export default new Router({
53
+ base: process.env.VUE_APP_APP_NAME ? process.env.VUE_APP_APP_NAME : "/",
54
+ // base: process.env.PUBLIC_PATH ? process.env.PUBLIC_PATH : "/",
55
+ mode: 'history', // 去掉url中的#
56
+ scrollBehavior: () => ({y: 0}),
57
+ routes: constantRoutes
58
+ })
@@ -0,0 +1,105 @@
1
+
2
+ const AccessTokenKey = 'ACCESS_TOKEN'
3
+ const RefreshTokenKey = 'REFRESH_TOKEN'
4
+
5
+ // ========== Token 相关 ==========
6
+
7
+ export function getAccessToken() {
8
+ return localStorage.getItem(AccessTokenKey)
9
+ }
10
+
11
+ export function getRefreshToken() {
12
+ return localStorage.getItem(RefreshTokenKey)
13
+ }
14
+
15
+ export function setToken(loginResp) {
16
+ localStorage.setItem(AccessTokenKey, loginResp.accessToken)
17
+ localStorage.setItem(RefreshTokenKey, loginResp.refreshToken)
18
+ }
19
+
20
+ export function removeToken() {
21
+ localStorage.removeItem(AccessTokenKey)
22
+ localStorage.removeItem(RefreshTokenKey)
23
+ }
24
+
25
+ // ========== 账号相关 ==========
26
+ const UserIdKey = 'USERID'
27
+ const UsernameKey = 'USERNAME'
28
+ const PasswordKey = 'PASSWORD'
29
+ const RememberMeKey = 'REMEMBER_ME'
30
+
31
+ export function getUserId() {
32
+ return localStorage.getItem(UserIdKey)
33
+ }
34
+
35
+ export function setUserId(userId) {
36
+ localStorage.setItem(UserIdKey, userId)
37
+ }
38
+ export function getUsername() {
39
+ return localStorage.getItem(UsernameKey)
40
+ }
41
+
42
+ export function setUsername(username) {
43
+ localStorage.setItem(UsernameKey, username)
44
+ }
45
+
46
+ export function removeUsername() {
47
+ localStorage.removeItem(UsernameKey)
48
+ }
49
+
50
+ export function getPassword() {
51
+ const password = localStorage.getItem(PasswordKey)
52
+ return password ? decrypt(password) : undefined
53
+ }
54
+
55
+ export function setPassword(password) {
56
+ localStorage.setItem(PasswordKey, encrypt(password))
57
+ }
58
+
59
+ export function removePassword() {
60
+ localStorage.removeItem(PasswordKey)
61
+ }
62
+
63
+ export function getRememberMe() {
64
+ return localStorage.getItem(RememberMeKey) === 'true'
65
+ }
66
+
67
+ export function setRememberMe(rememberMe) {
68
+ localStorage.setItem(RememberMeKey, rememberMe)
69
+ }
70
+
71
+ export function removeRememberMe() {
72
+ localStorage.removeItem(RememberMeKey)
73
+ }
74
+
75
+ // ========== 租户相关 ==========
76
+
77
+ const TenantIdKey = 'TENANT_ID'
78
+ const TenantNameKey = 'TENANT_NAME'
79
+
80
+ export function getTenantName() {
81
+ return localStorage.getItem(TenantNameKey)
82
+ }
83
+
84
+ export function setTenantName(username) {
85
+ localStorage.setItem(TenantNameKey, username)
86
+ }
87
+
88
+ export function removeTenantName() {
89
+ localStorage.removeItem(TenantNameKey)
90
+ }
91
+
92
+ export function getTenantId() {
93
+ return localStorage.getItem(TenantIdKey)
94
+ }
95
+
96
+ export function setTenantId(username) {
97
+ localStorage.setItem(TenantIdKey, username)
98
+ }
99
+
100
+ export function removeTenantId() {
101
+ localStorage.removeItem(TenantIdKey)
102
+ }
103
+
104
+ export class getToken {
105
+ }
@@ -0,0 +1,85 @@
1
+ import axios from 'axios'
2
+ import {Message, MessageBox, Notification, Loading} from 'element-ui'
3
+
4
+ // 需要忽略的提示。忽略后,自动 Promise.reject('error')
5
+ const ignoreMsgs = [
6
+ "无效的刷新令牌", // 刷新令牌被删除时,不用提示
7
+ "刷新令牌已过期" // 使用刷新令牌,刷新获取新的访问令牌时,结果因为过期失败,此时需要忽略。否则,会导致继续 401,无法跳转到登出界面
8
+ ]
9
+
10
+ // 是否显示重新登录
11
+ export let isRelogin = { show: false };
12
+ // Axios 无感知刷新令牌,参考 https://www.dashingdog.cn/article/11 与 https://segmentfault.com/a/1190000020210980 实现
13
+ // 请求队列
14
+ let requestList = []
15
+ // 是否正在刷新中
16
+ let isRefreshToken = false
17
+
18
+ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
19
+ // 创建axios实例
20
+ const service = axios.create({
21
+ // axios中请求配置有baseURL选项,表示请求URL公共部分
22
+ baseURL: process.env.VUE_APP_BASE_API + '/admin-api/', // 此处的 /admin-api/ 地址,原因是后端的基础路径为 /admin-api/
23
+ // 超时
24
+ timeout: 300000,
25
+ // 禁用 Cookie 等信息
26
+ withCredentials: false,
27
+ })
28
+ // request拦截器
29
+ service.interceptors.request.use(config => {
30
+ // get请求映射params参数
31
+ if (config.method === 'get' && config.params) {
32
+ let url = config.url + '?';
33
+ for (const propName of Object.keys(config.params)) {
34
+ const value = config.params[propName];
35
+ const part = encodeURIComponent(propName) + '='
36
+ if (value !== null && typeof(value) !== "undefined") {
37
+ if (typeof value === 'object') {
38
+ for (const key of Object.keys(value)) {
39
+ let params = propName + '[' + key + ']';
40
+ const subPart = encodeURIComponent(params) + '='
41
+ url += subPart + encodeURIComponent(value[key]) + "&";
42
+ }
43
+ } else {
44
+ url += part + encodeURIComponent(value) + "&";
45
+ }
46
+ }
47
+ }
48
+ url = url.slice(0, -1);
49
+ config.params = {};
50
+ config.url = url;
51
+ }
52
+ return config
53
+ }, error => {
54
+ console.log(error)
55
+ Promise.reject(error)
56
+ })
57
+
58
+ // 响应拦截器
59
+ service.interceptors.response.use(async res => {
60
+ if (res.status == 200) {
61
+ return res.data
62
+ } else {
63
+ Message.error(res.statusText || '请求失败')
64
+ }
65
+ }, error => {
66
+ console.log('err' + error)
67
+ let {message} = error;
68
+ if (message === "Network Error") {
69
+ message = "后端接口连接异常";
70
+ } else if (message.includes("timeout")) {
71
+ message = "系统接口请求超时";
72
+ } else if (message.includes("Request failed with status code")) {
73
+ message = "系统接口" + message.substr(message.length - 3) + "异常";
74
+ }
75
+ Message({
76
+ message: message,
77
+ type: 'error',
78
+ duration: 5 * 1000
79
+ })
80
+ return Promise.reject(error)
81
+ }
82
+ )
83
+
84
+
85
+ export default service
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <div style="border:0px solid #DDD; border-radius:5px;">
3
+ <!-- 人脸登陆 -->
4
+ <!-- <FaceLogin :tenantId="tenantId" :requestId="requestId" @success="handleSuccess" @error="handleFail" /> -->
5
+ <!-- 活体 + 人脸 登陆 -->
6
+ <AliveCheckLogin :tenantId="tenantId" :requestId="requestId" @success="handleSuccess" @error="handleFail" />
7
+ </div>
8
+ </template>
9
+
10
+ <script>
11
+ import { Message } from 'element-ui'
12
+ // import FaceLogin from '/packages/VueFaceLogin/FaceLogin'
13
+ // import AliveCheckLogin from '/packages/VueFaceLogin/AliveCheckLogin'
14
+ import * as auth from '@/utils/auth'
15
+
16
+ export default {
17
+ name: 'Login',
18
+ components: {
19
+ // AliveCheckLogin
20
+ },
21
+ data() {
22
+ return {
23
+ tenantId: 1,
24
+ requestId: undefined,
25
+ }
26
+ },
27
+ mounted() {
28
+ // 接受pc 端扫码的requestId,以便结果通知到pc端
29
+ this.requestId = this.$route.params.requestId || this.$route.query.requestId || (Date.now()+""+ parseInt(Math.random()*10000));
30
+ },
31
+ methods:{
32
+ handleSuccess(userToken){
33
+ console.log("success", userToken)
34
+ auth.setToken(userToken);
35
+ auth.setUserId(userToken.userId);
36
+ auth.setUsername(userToken.alias);
37
+ auth.setTenantId(userToken.tenantId);
38
+ Message.success("登陆成功")
39
+ this.$router.push({
40
+ path:"/"
41
+ })
42
+ },
43
+ handleFail(err){
44
+ console.log("error", err)
45
+ Message.error("登陆失败")
46
+ }
47
+ }
48
+
49
+ }
50
+
51
+ </script>
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <div style="border:0px solid #DDD; border-radius:5px;">
3
+ <el-button type="text" @click="goback">返回</el-button>
4
+ <div>
5
+ 隐私保护协议
6
+ </div>
7
+ </div>
8
+ </template>
9
+
10
+ <script>
11
+
12
+ export default {
13
+ name: 'Policy',
14
+ components: {
15
+
16
+ },
17
+ data() {
18
+ return {
19
+ }
20
+ },
21
+ mounted() {
22
+ },
23
+ methods:{
24
+ goback(){
25
+ this.$router.go(-1)
26
+ }
27
+ }
28
+ }
29
+
30
+ </script>
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <div style="border:0px solid #DDD; border-radius:5px;">
3
+ <el-link v-if="0" :underline="false" href="/" class="face-login-back"><i class="el-icon-arrow-left" /> 返回</el-link>
4
+ <FaceRegister :userId="115" :tenantId="1" @success="handleSuccess" @error="handleFail" />
5
+ </div>
6
+ </template>
7
+
8
+ <script>
9
+ // import FaceRegister from '/packages/VueFaceLogin/FaceRegister'
10
+ export default {
11
+ name: 'Register',
12
+ components: {
13
+ // FaceRegister
14
+ },
15
+ methods:{
16
+
17
+ handleSuccess(userToken){
18
+ console.log("success", userToken)
19
+ this.$router.push({
20
+ name: "Login"
21
+ })
22
+ },
23
+ handleFail(err){
24
+ console.log("error", err)
25
+ },
26
+ }
27
+
28
+ }
29
+
30
+ </script>
31
+