xiongzhu 4 سال پیش
والد
کامیت
b587512bd5

+ 1 - 1
android/app/src/main/assets/capacitor.config.json

@@ -1,6 +1,6 @@
 {
     "appId": "cn.drewslab.visitor",
-    "appName": "visitor",
+    "appName": "访客管理",
     "bundledWebRuntime": false,
     "npmClient": "yarn",
     "webDir": "dist",

+ 2 - 0
android/app/src/main/java/cn/drewslab/visitor/MainActivity.java

@@ -8,6 +8,7 @@ import com.getcapacitor.Plugin;
 import java.util.ArrayList;
 
 import com.dutchconcepts.capacitor.barcodescanner.BarcodeScanner;
+import com.getcapacitor.community.keepawake.KeepAwake;
 
 public class MainActivity extends BridgeActivity {
     @Override
@@ -19,6 +20,7 @@ public class MainActivity extends BridgeActivity {
             // Additional plugins you've installed go here
             // Ex: add(TotallyAwesomePlugin.class);
             add(BarcodeScanner.class);
+            add(KeepAwake.class);
         }});
     }
 }

+ 2 - 2
android/app/src/main/res/values/strings.xml

@@ -1,7 +1,7 @@
 <?xml version='1.0' encoding='utf-8'?>
 <resources>
-    <string name="app_name">visitor</string>
-    <string name="title_activity_main">visitor</string>
+    <string name="app_name">访客管理</string>
+    <string name="title_activity_main">访客管理</string>
     <string name="package_name">cn.drewslab.visitor</string>
     <string name="custom_url_scheme">cn.drewslab.visitor</string>
 </resources>

+ 1 - 1
capacitor.config.json

@@ -1,6 +1,6 @@
 {
     "appId": "cn.drewslab.visitor",
-    "appName": "visitor",
+    "appName": "访客管理",
     "bundledWebRuntime": false,
     "npmClient": "yarn",
     "webDir": "dist",

+ 1 - 0
package.json

@@ -20,6 +20,7 @@
     "vconsole-webpack-plugin": "^1.5.2",
     "vue": "^2.6.11",
     "vue-router": "^3.2.0",
+    "vueg": "^1.4.5",
     "vuex": "^3.4.0"
   },
   "devDependencies": {

+ 1 - 1
src/App.vue

@@ -1,5 +1,5 @@
 <template>
-    <router-view class="router-page" id="root"></router-view>
+    <router-view class="router-page" id="root" v-transition></router-view>
 </template>
 
 <style lang="less">

BIN
src/assets/line.png


+ 16 - 1
src/components/NavBar.vue

@@ -1,6 +1,6 @@
 <template>
     <div :style="computedStyle">
-        <div class="app-nav-bar" :style="navBarStyle">
+        <div class="app-nav-bar" :class="[{ transparent: transparent }, this.theme]">
             <div class="nav-bar-body">
                 <slot name="title">
                     <div class="nav-bar-title">{{ title }}</div>
@@ -141,6 +141,21 @@ export default {
             font-weight: 500;
         }
     }
+    &.dark {
+        background: white;
+        .nav-bar-title {
+            color: black;
+        }
+    }
+    &.light {
+        background: black;
+        .nav-bar-title {
+            color: white;
+        }
+    }
+    &.transparent {
+        background: transparent;
+    }
 }
 .nav-bar-placeholder {
     height: calc(44px + var(--safe-top));

+ 5 - 0
src/main.js

@@ -7,15 +7,20 @@ import Vant from 'vant';
 import 'vant/lib/index.less';
 import NavBar from './components/NavBar';
 import http from './plugins/http';
+import vueg from 'vueg';
 Vue.config.productionTip = false;
 Vue.use(Vant);
 Vue.component('nav-bar', NavBar);
 Vue.use(http);
+Vue.use(vueg, router, {});
 
 const { StatusBar } = Plugins;
 StatusBar.setOverlaysWebView({
     overlay: true
 });
+if (process.env.NODE_ENV === 'development') {
+    Plugins.KeepAwake.keepAwake();
+}
 
 const vm = new Vue({
     router,

+ 3 - 0
src/styles/app.less

@@ -297,3 +297,6 @@ input {
 ::-webkit-scrollbar {
     display: none;
 }
+#vueg-background {
+    background: transparent !important;
+}

+ 3 - 0
src/views/Home.vue

@@ -1,5 +1,8 @@
 <template>
     <div class="home">
+        <nav-bar title="访客管理系统">
+            <div slot="left"></div>
+        </nav-bar>
         <div class="scan" @click="scan">
             <van-icon name="scan" />
             <div class="desc">点击扫码</div>

+ 102 - 30
src/views/scan.vue

@@ -1,48 +1,75 @@
 <template>
-    <div>
-        <nav-bar theme="light" @click-left="$router.go(-1)" transparent></nav-bar>
+    <div class="scan">
+        <nav-bar title="扫码" theme="light" @click-left="$router.go(-1)" transparent></nav-bar>
+        <img src="../assets/line.png" class="scan-line" />
+        <div class="tip">扫描二维码/条码</div>
     </div>
 </template>
 <script>
 import { Plugins } from '@capacitor/core';
 const { BarcodeScanner } = Plugins;
 export default {
-    mounted() {
+    async mounted() {
         BarcodeScanner.hideBackground();
+        this.bodyBackgorund = window.getComputedStyle(document.body).background;
+        this.appBackground = window.getComputedStyle(this.$el.parentElement).background;
         document.body.style.background = 'transparent';
-        document.querySelector('#root').style.background = 'transparent';
-        this.startScan();
+        this.$el.parentElement.style.background = 'transparent';
+        console.log('mounted');
+        if (await this.checkPermission()) {
+            setTimeout(() => {
+                this.startScan();
+                this.$el.style.background = 'transparent';
+            }, 300);
+        } else {
+            this.$router.go(-1);
+        }
     },
     data() {
         return {
-            async checkPermission() {
-                // check or request permission
-                const status = await BarcodeScanner.checkPermission({ force: true });
+            bodyBackgorund: '',
+            appBackground: ''
+        };
+    },
+    methods: {
+        async checkPermission() {
+            // check or request permission
+            const status = await BarcodeScanner.checkPermission({ force: true });
 
-                if (status.granted) {
-                    // the user granted permission
-                    return true;
-                }
-                return false;
-            },
-            async startScan() {
-                if (!this.checkPermission()) {
-                    return;
-                }
+            if (status.granted) {
+                // the user granted permission
+                return true;
+            }
 
-                BarcodeScanner.hideBackground(); // make background of WebView transparent
-                const result = BarcodeScanner.startScan(); // start scanning and wait for a result
+            if (status.denied) {
+                // the user denied permission for good
+                // redirect user to app settings if they want to grant it anyway
+                try {
+                    await this.$dialog.confirm({
+                        title: '提示',
+                        message: '需要获取相机权限'
+                    });
+                    BarcodeScanner.openAppSettings();
+                } catch (error) {}
+            }
+            return false;
+        },
+        async startScan() {
+            BarcodeScanner.hideBackground(); // make background of WebView transparent
+            const result = await BarcodeScanner.startScan(); // start scanning and wait for a result
 
-                // if the result has content
-                if (result.hasContent) {
-                    console.log(result.content); // log the raw scanned content
-                }
-            },
-            stopScan() {
-                BarcodeScanner.showBackground();
-                BarcodeScanner.stopScan();
+            // if the result has content
+            if (result.hasContent) {
+                console.log(result.content); // log the raw scanned content
+                document.body.style.background = this.bodyBackgorund;
+                this.$el.parentElement.background = this.appBackground;
+                this.$router.go(-1);
             }
-        };
+        },
+        stopScan() {
+            BarcodeScanner.showBackground();
+            BarcodeScanner.stopScan();
+        }
     },
     deactivated() {
         this.stopScan();
@@ -52,4 +79,49 @@ export default {
     }
 };
 </script>
-<style lang="sass" scoped></style>
+<style lang="less" scoped>
+.scan {
+    background: black;
+    transition: all 0.3s;
+}
+.scan-line {
+    width: 100%;
+    height: auto;
+    position: relative;
+    animation: mymove 2s infinite, myfade 3s infinite;
+    animation-duration: 2s, 2s;
+    animation-timing-function: linear, linear;
+    animation-iteration-count: infinite, infinite;
+}
+@keyframes mymove {
+    0% {
+        top: 0px;
+    }
+    100% {
+        top: 50vh;
+    }
+}
+@keyframes myfade {
+    0% {
+        opacity: 0;
+    }
+    5% {
+        opacity: 1;
+    }
+    75% {
+        opacity: 1;
+    }
+    100% {
+        opacity: 0;
+    }
+}
+.tip {
+    color: rgba(255, 255, 255, 0.7);
+    font-size: 14px;
+    position: absolute;
+    bottom: calc(80px + var(--safe-bottom));
+    text-align: center;
+    left: 0;
+    right: 0;
+}
+</style>

+ 12 - 0
yarn.lock

@@ -1647,6 +1647,11 @@ alphanum-sort@^1.0.0:
   resolved "https://registry.npm.taobao.org/alphanum-sort/download/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
   integrity sha1-l6ERlkmyEa0zaR2fn0hqjsn74KM=
 
+animate.css@^3.7.0:
+  version "3.7.2"
+  resolved "https://registry.yarnpkg.com/animate.css/-/animate.css-3.7.2.tgz#e73e0d50e92cb1cfef1597d9b38a9481020e08ea"
+  integrity sha512-0bE8zYo7C0KvgOYrSVfrzkbYk6IOTVPNqkiHg2cbyF4Pq/PXzilz4BRWA3hwEUBoMp5VBgrC29lQIZyhRWdBTw==
+
 ansi-colors@^3.0.0:
   version "3.2.4"
   resolved "https://registry.npm.taobao.org/ansi-colors/download/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf"
@@ -8485,6 +8490,13 @@ vue@^2.6.11:
   resolved "https://registry.npm.taobao.org/vue/download/vue-2.6.12.tgz?cache=0&sync_timestamp=1614614651009&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue%2Fdownload%2Fvue-2.6.12.tgz#f5ebd4fa6bd2869403e29a896aed4904456c9123"
   integrity sha1-9evU+mvShpQD4pqJau1JBEVskSM=
 
+vueg@^1.4.5:
+  version "1.4.5"
+  resolved "https://registry.yarnpkg.com/vueg/-/vueg-1.4.5.tgz#52d54e11ecde1e696368a247a4aa09d836ebfa84"
+  integrity sha512-Q+UTTLPZ1yIZp4zQPNBQVMdKTsgINfArzQDVGpiM7Ga02WZ4kkND14v0OfW+BEYV6pd8d8WdT6SILPBCzF3F8A==
+  dependencies:
+    animate.css "^3.7.0"
+
 vuex@^3.4.0:
   version "3.6.2"
   resolved "https://registry.npm.taobao.org/vuex/download/vuex-3.6.2.tgz?cache=0&sync_timestamp=1612277442796&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvuex%2Fdownload%2Fvuex-3.6.2.tgz#236bc086a870c3ae79946f107f16de59d5895e71"