Skip to content

Commit 77291ba

Browse files
committed
♻️ Refactoring code
1 parent c3841a4 commit 77291ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+845
-937
lines changed

src/App.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
* @Author: GitHubGanKai
55
* @Date: 2020-04-29 22:08:12
66
* @LastEditors: gankai
7-
* @LastEditTime: 2020-12-28 00:36:36
7+
* @LastEditTime: 2021-01-02 14:32:14
88
* @FilePath: /refactor-with-vue3/src/App.vue
99
-->
1010
<template>
11-
<div id="app">
12-
<keep-alive>
13-
<router-view />
14-
</keep-alive>
15-
</div>
11+
<keep-alive>
12+
<router-view />
13+
</keep-alive>
1614
</template>
1715

1816
<script>

src/components/ProgressBar/index.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<!--
2+
* @version: v 1.0.0
3+
* @Github: https://github.com/GitHubGanKai
4+
* @Author: GitHubGanKai
5+
* @Date: 2021-01-01 17:19:50
6+
* @LastEditors: gankai
7+
* @LastEditTime: 2021-01-02 20:33:51
8+
* @FilePath: /refactor-with-vue3/src/components/ProgressBar/index.vue
9+
-->
110
<template>
211
<div class="progress-bar-box">
312
<div class="progress-bar">
@@ -17,8 +26,8 @@ export default {
1726
},
1827
created() {},
1928
methods: {
20-
processbar() {},
21-
},
29+
processbar() {}
30+
}
2231
};
2332
</script>
2433

src/components/SvgIcon/index.vue

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @Author: GitHubGanKai
55
* @Date: 2020-04-29 22:08:12
66
* @LastEditors: gankai
7-
* @LastEditTime: 2020-05-02 23:58:59
8-
* @FilePath: /vue-jd-h5/src/components/SvgIcon/index.vue
7+
* @LastEditTime: 2021-01-02 20:34:09
8+
* @FilePath: /refactor-with-vue3/src/components/SvgIcon/index.vue
99
-->
1010
<template>
1111
<svg :class="svgClass" aria-hidden="true">
@@ -14,13 +14,7 @@
1414
</template>
1515

1616
<script>
17-
import {
18-
ref,
19-
reactive,
20-
onMounted,
21-
computed,
22-
getCurrentInstance
23-
} from "vue";
17+
import { ref, reactive, onMounted, computed, getCurrentInstance } from "vue";
2418
export default {
2519
name: "svg-icon",
2620
props: {

src/components/index.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,31 @@
44
* @Author: GitHubGanKai
55
* @Date: 2021-01-01 13:57:27
66
* @LastEditors: gankai
7-
* @LastEditTime: 2021-01-01 14:20:32
7+
* @LastEditTime: 2021-01-02 13:27:58
88
* @FilePath: /refactor-with-vue3/src/components/index.js
99
*/
10-
import Vue from 'vue'
1110

12-
/**
13-
* 首字母大写
14-
* @param str 字符串
15-
* @example heheHaha
16-
* @return {string} HeheHaha
17-
*/
1811
function capitalizeFirstLetter(str) {
1912
return str.charAt(0).toUpperCase() + str.slice(1)
2013
}
2114

22-
/**
23-
* 对符合'xx/xx.vue'组件格式的组件取组件名
24-
* @param str fileName
25-
* @example abc/bcd/def/basicTable.vue
26-
* @return {string} BasicTable
27-
*/
2815
function validateFileName(str) {
2916
return /^\S+\.vue$/.test(str) &&
3017
str.replace(/^\S+\/(\w+)\.vue$/, (rs, $1) => capitalizeFirstLetter($1))
3118
}
3219

3320
const requireComponent = require.context('.', true, /\.vue$/)
3421

35-
// 找到组件文件夹下以.vue命名的文件,如果文件名为index,那么取组件中的name作为注册的组件名
36-
requireComponent.keys().forEach(filePath => {
37-
const componentConfig = requireComponent(filePath)
38-
const fileName = validateFileName(filePath)
39-
const componentName = fileName.toLowerCase() === 'index' ?
40-
capitalizeFirstLetter(componentConfig.default.name) :
41-
fileName
42-
Vue.component(componentName, componentConfig.default || componentConfig)
43-
})
22+
export default {
23+
install(app) {
24+
// 找到组件文件夹下以.vue命名的文件,如果文件名为index,那么取组件中的name作为注册的组件名
25+
requireComponent.keys().forEach(filePath => {
26+
const componentConfig = requireComponent(filePath)
27+
const fileName = validateFileName(filePath)
28+
const componentName = fileName.toLowerCase() === 'index' ?
29+
capitalizeFirstLetter(componentConfig.default.name) :
30+
fileName
31+
app.component(componentName, componentConfig.default || componentConfig)
32+
})
33+
}
34+
}

src/components/picker/index.vue

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,30 @@ export default {
8282
props: {
8383
show: {
8484
type: Boolean,
85-
default: false,
85+
default: false
8686
},
8787
defaultData: {
8888
type: Array,
8989
default() {
9090
return [];
91-
},
91+
}
9292
},
9393
columns: {
9494
type: Number,
95-
default: 1,
95+
default: 1
9696
},
9797
link: {
9898
type: Boolean,
99-
default: false,
99+
default: false
100100
},
101101
selectData: {
102102
type: Object,
103-
default: {},
103+
default: {}
104104
},
105105
isRemember: {
106106
type: Boolean,
107-
default: false,
108-
},
107+
default: false
108+
}
109109
},
110110
data() {
111111
return {
@@ -116,18 +116,18 @@ export default {
116116
selects: {
117117
select1: "",
118118
select2: "",
119-
select3: "",
119+
select3: ""
120120
},
121121
noData: false,
122-
isOpened: 0,
122+
isOpened: 0
123123
};
124124
},
125125
methods: {
126-
close: function (e) {
126+
close: function(e) {
127127
this.$emit("cancel");
128128
e.preventDefault();
129129
},
130-
finish: function (e) {
130+
finish: function(e) {
131131
this.$emit("confirm", JSON.parse(JSON.stringify(this.selects)));
132132
e.preventDefault();
133133
},
@@ -217,7 +217,7 @@ export default {
217217
stopGear = true;
218218
}
219219
clearInterval(target["int_" + target.id]);
220-
target["int_" + target.id] = setInterval(function () {
220+
target["int_" + target.id] = setInterval(function() {
221221
var pos = target["pos_" + target.id];
222222
var speed = target["spd_" + target.id] * Math.exp(-0.03 * d);
223223
pos += speed;
@@ -399,25 +399,25 @@ export default {
399399
this.selects.select2 = this.pData2[0];
400400
this.selects.select3 = this.pData3[0];
401401
}
402-
},
402+
}
403403
},
404404
mounted() {
405405
this.init();
406406
},
407407
watch: {
408408
selectData: {
409-
handler: function () {
409+
handler: function() {
410410
this.init();
411411
},
412-
deep: true,
412+
deep: true
413413
},
414414
show(val) {
415415
if (val) {
416416
this.isOpened += 1;
417417
this.setTop(this.defaultData || []);
418418
}
419-
},
420-
},
419+
}
420+
}
421421
};
422422
</script>
423423

@@ -604,4 +604,4 @@ export default {
604604
flex-direction: column;
605605
overflow: hidden;
606606
}
607-
</style>
607+
</style>

src/components/popup/index.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<!--
2+
* @version: v 1.0.0
3+
* @Github: https://github.com/GitHubGanKai
4+
* @Author: GitHubGanKai
5+
* @Date: 2021-01-01 17:19:50
6+
* @LastEditors: gankai
7+
* @LastEditTime: 2021-01-02 20:33:24
8+
* @FilePath: /refactor-with-vue3/src/components/popup/index.vue
9+
-->
110
<template>
211
<div class="popup" v-show="popupShow">
312
<div class="popup-content">
@@ -21,21 +30,21 @@ export default {
2130
props: {
2231
popupShow: {
2332
type: Boolean,
24-
default: false,
33+
default: false
2534
},
2635
popupTitle: {
2736
type: String,
28-
default: "",
29-
},
37+
default: ""
38+
}
3039
},
3140
methods: {
3241
cancelPopup() {
3342
this.$emit("cancelPopup");
3443
},
3544
confirmPopup() {
3645
this.$emit("confirmPopup");
37-
},
38-
},
46+
}
47+
}
3948
};
4049
</script>
4150

0 commit comments

Comments
 (0)