1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
| <template>
| <view @click="gotoPage()"><slot></slot></view>
| </template>
|
| <script>
| const navType = {
| push: 'push',
| replace: 'replace',
| replaceAll: 'replaceAll',
| pushTab: 'pushTab'
| };
| export default {
| props: {
| to: {
| type: [String, Object],
| },
| stopNavto: {
| type: Boolean,
| default: false
| },
| navType: {
| type: String,
| default: 'push'
| },
| level: {
| type: Number,
| default: 1
| },
| append: {
| type: Boolean,
| default: false
| }
| },
| methods: {
| formatNav(text) {
| if (text != null && text.constructor === String) {
| text = text.replace(/\'/g, '');
| text = text.replace(/(\w+)(?=:)/g, function(val) {
| return `"${val}"`;
| });
| text = text.replace(/:\s*([^,{}\s"]+)/g, function(val) {
| const arr = val.split(':');
| return `:"${arr[1].trim()}"`;
| });
| try {
| text = JSON.parse(text);
| } catch (e) {}
| }
| if (this.append) {
| let pathArr = this.$Route.path.split('/');
| pathArr.splice(pathArr.length - this.level, this.level);
| pathArr = pathArr.join('/');
| if (text.constructor === Object) {
| if (text.path) {
| text.path = pathArr + text.path;
| }
| } else {
| text = pathArr + text;
| }
| }
| return text;
| },
| gotoPage() {
| if (this.stopNavto) {
| return true;
| }
| const type = navType[this.navType];
| if (type == null) {
| return console.error(` "navType" unknown type \n\n value:${Object.values(navType).join('、')}`);
| }
| const navInfo = this.formatNav(this.to);
|
| this.$Router[type](navInfo);
| }
| }
| };
| </script>
|
| <style></style>
|
|