张延森 4 년 전
부모
커밋
62d1f79529
6개의 변경된 파일93개의 추가작업 그리고 1개의 파일을 삭제
  1. 1
    0
      package.json
  2. 61
    0
      src/components/XLoading/index.vue
  3. 9
    1
      src/main.js
  4. 8
    0
      src/store/index.js
  5. 9
    0
      src/store/models/loading.js
  6. 5
    0
      yarn.lock

+ 1
- 0
package.json 파일 보기

@@ -8,6 +8,7 @@
8 8
     "lint": "vue-cli-service lint"
9 9
   },
10 10
   "dependencies": {
11
+    "@zjxpcyc/vue-tiny-store": "^1.0.1",
11 12
     "core-js": "^3.6.5",
12 13
     "vant": "^3.0.0",
13 14
     "vue": "^3.0.0",

+ 61
- 0
src/components/XLoading/index.vue 파일 보기

@@ -0,0 +1,61 @@
1
+<template>
2
+  <div class="x-loading">
3
+    <div v-show="show" class="loadding-wrapper">
4
+      <div class="loading-flex">
5
+        <div style="flex:none">
6
+          <van-loading :color="color || '#1989fa'">{{tip}}</van-loading>
7
+        </div>
8
+      </div>
9
+    </div>
10
+    <slot></slot>
11
+  </div>
12
+</template>
13
+
14
+<script>
15
+import { computed } from 'vue'
16
+import { Loading } from 'vant'
17
+import { useModel } from '@zjxpcyc/vue-tiny-store'
18
+// import store from '../../store'
19
+
20
+export default {
21
+  components: {
22
+    [Loading.name]: Loading,
23
+  },
24
+  props: {
25
+    color: String,
26
+    tip: String,
27
+    xId: String,
28
+  },
29
+  setup(props) {
30
+    const { loading } = useModel('loading')
31
+
32
+    const show = computed(() => loading[props.xId])
33
+
34
+    return {
35
+      show
36
+    }
37
+  }
38
+}
39
+</script>
40
+
41
+<style lang="less" scoped>
42
+.x-loading {
43
+  position: relative;
44
+
45
+  .loadding-wrapper {
46
+    width: 100%;
47
+    height: 100%;
48
+    background: rgba(255, 255, 255, .9);
49
+    z-index: 9999;
50
+    position: absolute;
51
+    top: 0;
52
+    left: 0;
53
+
54
+    .loading-flex {
55
+      display: flex;
56
+      justify-content: center;
57
+      align-items: center;
58
+    }
59
+  }
60
+}
61
+</style>

+ 9
- 1
src/main.js 파일 보기

@@ -2,7 +2,15 @@
2 2
 import { createApp } from 'vue';
3 3
 import App from './App.vue';
4 4
 import { router } from './router';
5
+import store from './store'
5 6
 import 'vant/lib/index.css';
7
+
8
+import XLoading from './components/XLoading'
9
+
6 10
 const app = createApp(App);
11
+app.use(store);
7 12
 app.use(router);
8
-app.mount('#app');
13
+
14
+app.component('x-loading', XLoading)
15
+
16
+app.mount('#app');

+ 8
- 0
src/store/index.js 파일 보기

@@ -0,0 +1,8 @@
1
+import createStore from '@zjxpcyc/vue-tiny-store'
2
+import loading from './models/loading'
3
+
4
+const store = createStore({
5
+  loading,
6
+})
7
+
8
+export default store

+ 9
- 0
src/store/models/loading.js 파일 보기

@@ -0,0 +1,9 @@
1
+import { reactive } from "@vue/reactivity"
2
+
3
+export default () => {
4
+  const loading = reactive({})
5
+
6
+  const setLoading = (id, state) => loading[id] = state
7
+
8
+  return { loading, setLoading }
9
+}

+ 5
- 0
yarn.lock 파일 보기

@@ -1625,6 +1625,11 @@
1625 1625
   resolved "https://registry.npm.taobao.org/@xtuc/long/download/@xtuc/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
1626 1626
   integrity sha1-0pHGpOl5ibXGHZrPOWrk/hM6cY0=
1627 1627
 
1628
+"@zjxpcyc/vue-tiny-store@^1.0.1":
1629
+  version "1.0.1"
1630
+  resolved "https://registry.npm.taobao.org/@zjxpcyc/vue-tiny-store/download/@zjxpcyc/vue-tiny-store-1.0.1.tgz#9e67c0f08e9bddd802bdcb543a28c18181e27395"
1631
+  integrity sha1-nmfA8I6b3dgCvctUOijBgYHic5U=
1632
+
1628 1633
 accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.7:
1629 1634
   version "1.3.7"
1630 1635
   resolved "https://registry.npm.taobao.org/accepts/download/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"