@10yun/cv-mobile-ui 0.5.19 → 0.5.20
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/other/mpvue-picker/mpvuePicker.vue +402 -0
- package/{uni-ui/lib → other}/mpvue-picker/style.css +0 -1
- package/{uni-ui/lib → other}/tab-nvue/style.css +0 -1
- package/other/uParse/components/style.css +1 -0
- package/other/uParse/components/wxParseAudio.vue +1 -0
- package/other/uParse/components/wxParseImg.vue +86 -0
- package/other/uParse/components/wxParseTable.vue +54 -0
- package/other/uParse/components/wxParseTemplate0.vue +98 -0
- package/other/uParse/components/wxParseTemplate1.vue +81 -0
- package/other/uParse/components/wxParseTemplate10.vue +81 -0
- package/other/uParse/components/wxParseTemplate11.vue +79 -0
- package/other/uParse/components/wxParseTemplate2.vue +81 -0
- package/other/uParse/components/wxParseTemplate3.vue +81 -0
- package/other/uParse/components/wxParseTemplate4.vue +81 -0
- package/other/uParse/components/wxParseTemplate5.vue +81 -0
- package/other/uParse/components/wxParseTemplate6.vue +81 -0
- package/other/uParse/components/wxParseTemplate7.vue +81 -0
- package/other/uParse/components/wxParseTemplate8.vue +81 -0
- package/other/uParse/components/wxParseTemplate9.vue +81 -0
- package/other/uParse/components/wxParseVideo.vue +14 -0
- package/other/uParse/editor.css +495 -0
- package/{uni-ui/lib/uParse/src → other/uParse}/libs/html2json.js +19 -22
- package/{uni-ui/lib/uParse/src → other/uParse}/libs/htmlparser.js +12 -5
- package/{uni-ui/lib/uParse/src → other/uParse}/libs/wxDiscode.js +2 -2
- package/other/uParse/wxParse.vue +196 -0
- package/package.json +1 -1
- package/plugins/map/amqp-wx.js +173 -0
- package/{uni-ui/lib/mpvueGestureLock/index.vue → ui-cv/components/cv-draw-gesture-lock/cv-draw-gesture-lock.vue} +4 -1
- package/ui-cv/components/cv-draw-gesture-lock/gestureLock.js +169 -0
- package/{uni-ui/lib/mpvueGestureLock → ui-cv/components/cv-draw-gesture-lock}/style.css +0 -1
- package/{uni-ui/lib/mpvue-citypicker → ui-cv/components/cv-geo-region}/style.css +0 -1
- package/uni-ui/lib/amap-wx/js/util.js +0 -181
- package/uni-ui/lib/marked/index.js +0 -1
- package/uni-ui/lib/mpvue-citypicker/city-data/area.js +0 -12542
- package/uni-ui/lib/mpvue-citypicker/city-data/city.js +0 -1503
- package/uni-ui/lib/mpvue-citypicker/city-data/province.js +0 -139
- package/uni-ui/lib/mpvue-picker/mpvuePicker.vue +0 -3
- package/uni-ui/lib/mpvueGestureLock/gestureLock.js +0 -175
- package/uni-ui/lib/uParse/src/components/style.css +0 -2
- package/uni-ui/lib/uParse/src/components/wxParseAudio.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseImg.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTable.vue +0 -3
- package/uni-ui/lib/uParse/src/components/wxParseTemplate0.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate1.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate10.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate11.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate2.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate3.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate4.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate5.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate6.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate7.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate8.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseTemplate9.vue +0 -1
- package/uni-ui/lib/uParse/src/components/wxParseVideo.vue +0 -1
- package/uni-ui/lib/uParse/src/editor.css +0 -495
- package/uni-ui/lib/uParse/src/wxParse.vue +0 -1
- /package/{uni-ui/lib → other}/api-set-tabbar.nvue +0 -0
- /package/{uni-ui/lib → other}/mpvue-echarts/src/echarts.vue +0 -0
- /package/{uni-ui/lib → other}/mpvue-echarts/src/style.css +0 -0
- /package/{uni-ui/lib → other}/mpvue-echarts/src/wx-canvas.js +0 -0
- /package/{uni-ui/lib → other}/product.vue +0 -0
- /package/{uni-ui/lib → other}/style.css +0 -0
- /package/{uni-ui/lib → other}/tab-nvue/mediaList.vue +0 -0
- /package/{uni-ui/lib → other}/u-charts/u-charts.js +0 -0
- /package/{uni-ui/lib/uParse/src → other/uParse}/wxParse.css +0 -0
- /package/{uni-ui/lib/amap-wx → plugins/map}/lib/amap-wx.js +0 -0
- /package/{uni-ui/lib/mpvue-citypicker → ui-cv/components/cv-geo-region}/mpvueCityPicker.vue +0 -0
- /package/{uni-ui/lib/marked → ui-cv/components/cv-markdown-show}/lib/marked.js +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<!--**
|
|
2
|
+
* forked from:https://github.com/F-loat/mpvue-wxParse
|
|
3
|
+
*
|
|
4
|
+
* github地址: https://github.com/dcloudio/uParse
|
|
5
|
+
*
|
|
6
|
+
* uni-app框架下 富文本解析
|
|
7
|
+
*
|
|
8
|
+
*/-->
|
|
9
|
+
<template>
|
|
10
|
+
<!--基础元素-->
|
|
11
|
+
<div class="wxParse" :class="className" :style="'user-select:' + userSelect" v-if="!loading">
|
|
12
|
+
<block v-for="(node, index) of nodes" :key="index">
|
|
13
|
+
<wxParseTemplate :node="node" />
|
|
14
|
+
</block>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
<script>
|
|
18
|
+
import HtmlToJson from './libs/html2json';
|
|
19
|
+
import wxParseTemplate from './components/wxParseTemplate0';
|
|
20
|
+
export default {
|
|
21
|
+
name: 'wxParse',
|
|
22
|
+
props: {
|
|
23
|
+
// user-select:none;
|
|
24
|
+
userSelect: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: 'none' //none |text| all | element
|
|
27
|
+
},
|
|
28
|
+
imgOptions: {
|
|
29
|
+
type: [Object, Boolean],
|
|
30
|
+
default: function () {
|
|
31
|
+
return {
|
|
32
|
+
loop: false,
|
|
33
|
+
indicator: 'number',
|
|
34
|
+
longPressActions: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
loading: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: false
|
|
41
|
+
},
|
|
42
|
+
className: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: ''
|
|
45
|
+
},
|
|
46
|
+
content: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: ''
|
|
49
|
+
},
|
|
50
|
+
noData: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: ''
|
|
53
|
+
},
|
|
54
|
+
startHandler: {
|
|
55
|
+
type: Function,
|
|
56
|
+
default() {
|
|
57
|
+
return (node) => {
|
|
58
|
+
node.attr.class = null;
|
|
59
|
+
node.attr.style = null;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
endHandler: {
|
|
64
|
+
type: Function,
|
|
65
|
+
default: null
|
|
66
|
+
},
|
|
67
|
+
charsHandler: {
|
|
68
|
+
type: Function,
|
|
69
|
+
default: null
|
|
70
|
+
},
|
|
71
|
+
imageProp: {
|
|
72
|
+
type: Object,
|
|
73
|
+
default() {
|
|
74
|
+
return {
|
|
75
|
+
mode: 'aspectFit',
|
|
76
|
+
padding: 0,
|
|
77
|
+
lazyLoad: false,
|
|
78
|
+
domain: ''
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
components: {
|
|
84
|
+
wxParseTemplate
|
|
85
|
+
},
|
|
86
|
+
data() {
|
|
87
|
+
return {
|
|
88
|
+
nodes: {},
|
|
89
|
+
imageUrls: [],
|
|
90
|
+
wxParseWidth: {
|
|
91
|
+
value: 0
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
computed: {},
|
|
96
|
+
mounted() {
|
|
97
|
+
this.setHtml();
|
|
98
|
+
},
|
|
99
|
+
methods: {
|
|
100
|
+
setHtml() {
|
|
101
|
+
this.getWidth().then((data) => {
|
|
102
|
+
this.wxParseWidth.value = data;
|
|
103
|
+
});
|
|
104
|
+
let { content, noData, imageProp, startHandler, endHandler, charsHandler } = this;
|
|
105
|
+
let parseData = content || noData;
|
|
106
|
+
let customHandler = {
|
|
107
|
+
start: startHandler,
|
|
108
|
+
end: endHandler,
|
|
109
|
+
chars: charsHandler
|
|
110
|
+
};
|
|
111
|
+
let results = HtmlToJson(parseData, customHandler, imageProp, this);
|
|
112
|
+
this.imageUrls = results.imageUrls;
|
|
113
|
+
// this.nodes = results.nodes;
|
|
114
|
+
this.nodes = [];
|
|
115
|
+
results.nodes.forEach((item) => {
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
this.nodes.push(item);
|
|
118
|
+
}, 0);
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
getWidth() {
|
|
122
|
+
return new Promise((res, rej) => {
|
|
123
|
+
// #ifndef MP-ALIPAY || MP-BAIDU
|
|
124
|
+
uni
|
|
125
|
+
.createSelectorQuery()
|
|
126
|
+
.in(this)
|
|
127
|
+
.select('.wxParse')
|
|
128
|
+
.fields(
|
|
129
|
+
{
|
|
130
|
+
size: true,
|
|
131
|
+
scrollOffset: true
|
|
132
|
+
},
|
|
133
|
+
(data) => {
|
|
134
|
+
res(data.width);
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
.exec();
|
|
138
|
+
// #endif
|
|
139
|
+
// #ifdef MP-BAIDU
|
|
140
|
+
return new Promise((res, rej) => {
|
|
141
|
+
swan
|
|
142
|
+
.createSelectorQuery()
|
|
143
|
+
.select('.wxParse')
|
|
144
|
+
.boundingClientRect(function (rect) {
|
|
145
|
+
res(rect.width);
|
|
146
|
+
})
|
|
147
|
+
.exec();
|
|
148
|
+
});
|
|
149
|
+
// #endif
|
|
150
|
+
// #ifdef MP-ALIPAY
|
|
151
|
+
my.createSelectorQuery()
|
|
152
|
+
.select('.wxParse')
|
|
153
|
+
.boundingClientRect()
|
|
154
|
+
.exec((ret) => {
|
|
155
|
+
res(ret[0].width);
|
|
156
|
+
});
|
|
157
|
+
// #endif
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
navigate(href, $event, attr) {
|
|
161
|
+
console.log(href, attr);
|
|
162
|
+
this.$emit('navigate', href, $event);
|
|
163
|
+
},
|
|
164
|
+
preview(src, $event) {
|
|
165
|
+
if (!this.imageUrls.length || typeof this.imgOptions === 'boolean') {
|
|
166
|
+
} else {
|
|
167
|
+
uni.previewImage({
|
|
168
|
+
current: src,
|
|
169
|
+
urls: this.imageUrls,
|
|
170
|
+
loop: this.imgOptions.loop,
|
|
171
|
+
indicator: this.imgOptions.indicator,
|
|
172
|
+
longPressActions: this.imgOptions.longPressActions
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
this.$emit('preview', src, $event);
|
|
176
|
+
},
|
|
177
|
+
removeImageUrl(src) {
|
|
178
|
+
const { imageUrls } = this;
|
|
179
|
+
imageUrls.splice(imageUrls.indexOf(src), 1);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
// 父组件中提供
|
|
183
|
+
provide() {
|
|
184
|
+
return {
|
|
185
|
+
parseWidth: this.wxParseWidth,
|
|
186
|
+
parseSelect: this.userSelect
|
|
187
|
+
// 提示:provide 和 inject 绑定并不是可响应的。这是刻意为之的。然而,如果你传入了一个可监听的对象,那么其对象的属性还是可响应的。
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
watch: {
|
|
191
|
+
content() {
|
|
192
|
+
this.setHtml();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
</script>
|
package/package.json
CHANGED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import amap from './lib/amap-wx.js';
|
|
2
|
+
// 地铁颜色图
|
|
3
|
+
const line = {
|
|
4
|
+
'1号线': '#C43B33',
|
|
5
|
+
'2号线': '#016299',
|
|
6
|
+
'4号线/大兴线': '#008E9C',
|
|
7
|
+
'5号线': '#A42380',
|
|
8
|
+
'6号线': '#D09900',
|
|
9
|
+
'7号线': '#F2C172',
|
|
10
|
+
'8号线': '#009D6A',
|
|
11
|
+
'9号线': '#8FC41E',
|
|
12
|
+
'10号线': '#009DBE',
|
|
13
|
+
'13号线': '#F9E701',
|
|
14
|
+
'14号线东段': '#D4A7A2',
|
|
15
|
+
'14号线西段': '#D4A7A2',
|
|
16
|
+
'15号线': '#5D2D69',
|
|
17
|
+
八通线: '#C33A32',
|
|
18
|
+
昌平线: '#DE82B1',
|
|
19
|
+
亦庄线: '#E40177',
|
|
20
|
+
房山线: '#E66021',
|
|
21
|
+
机场线: '#A29BBC'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// 150500:地铁站 ,150700:公交站 , 190700:地名地址
|
|
25
|
+
const typecode = [
|
|
26
|
+
{
|
|
27
|
+
id: '150500',
|
|
28
|
+
icon: 'icon-ditie'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: '150700',
|
|
32
|
+
icon: 'icon-gongjiao'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '190700',
|
|
36
|
+
icon: 'icon-gonglu'
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const util = {
|
|
41
|
+
key: 'b526b09b86cd2996e7732be8ab8c4430',
|
|
42
|
+
/**
|
|
43
|
+
* 初始化高德地图api
|
|
44
|
+
*/
|
|
45
|
+
mapInit() {
|
|
46
|
+
return new amap.AMapWX({
|
|
47
|
+
key: this.key
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
// 服务状态吗
|
|
51
|
+
typecode,
|
|
52
|
+
/**
|
|
53
|
+
* 获取地图颜色
|
|
54
|
+
*/
|
|
55
|
+
lineColor(name) {
|
|
56
|
+
if (line[name]) {
|
|
57
|
+
return line[name];
|
|
58
|
+
} else {
|
|
59
|
+
return '#ccc';
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* 关键字颜色变化
|
|
64
|
+
*/
|
|
65
|
+
serachNmme(val, name) {
|
|
66
|
+
let namestr = new RegExp(val);
|
|
67
|
+
let nameresult = `<div style="font-size: 14px;color: #333;line-height: 1.5;">
|
|
68
|
+
${name.replace(namestr, "<span style='color:#66ccff;'>" + val + '</span>')}
|
|
69
|
+
</div>`.trim();
|
|
70
|
+
|
|
71
|
+
return nameresult;
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* 地址转地铁线路
|
|
75
|
+
*/
|
|
76
|
+
addressToLine(address, type) {
|
|
77
|
+
let addr = address.split(';');
|
|
78
|
+
let dt = '';
|
|
79
|
+
addr.forEach((elm) => {
|
|
80
|
+
let color = '#cccccc';
|
|
81
|
+
if (type === typecode[0].id) {
|
|
82
|
+
color = this.lineColor(elm);
|
|
83
|
+
} else if (type === typecode[1].id) {
|
|
84
|
+
color = '#4075cb';
|
|
85
|
+
}
|
|
86
|
+
let style =
|
|
87
|
+
'margin:5px 0;margin-right:5px;padding:0 5px;background:' + color + ';font-size:12px;color:#fff;border-radius:3px;';
|
|
88
|
+
dt += `<div style=\'${style}\'>${elm}</div>`;
|
|
89
|
+
});
|
|
90
|
+
return `<div style="display:flex;flex-wrap: wrap;">${dt}</div>`;
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* 数据处理
|
|
94
|
+
*/
|
|
95
|
+
dataHandle(item, val) {
|
|
96
|
+
// 改变字体颜色
|
|
97
|
+
if (val) {
|
|
98
|
+
item.nameNodes = util.serachNmme(val, item.name);
|
|
99
|
+
} else {
|
|
100
|
+
item.nameNodes = `<div style="font-size: 14px;color: #333;line-height: 1.5;">${item.name}</div>`;
|
|
101
|
+
}
|
|
102
|
+
// 地址解析 地铁
|
|
103
|
+
if (item.typecode === util.typecode[0].id || item.typecode === util.typecode[1].id) {
|
|
104
|
+
item.addressNodes = util.addressToLine(item.address, item.typecode);
|
|
105
|
+
if (item.typecode === util.typecode[0].id) {
|
|
106
|
+
item.icon = util.typecode[0].icon;
|
|
107
|
+
} else if (item.typecode === util.typecode[1].id) {
|
|
108
|
+
item.icon = util.typecode[1].icon;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
item.addressNodes = `<span>${item.district}${item.address.length > 0 ? '·' + item.address : ''}</span>`.trim();
|
|
112
|
+
item.icon = 'icon-weizhi';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (item.location && item.location.length === 0) {
|
|
116
|
+
item.icon = 'icon-sousuo';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return item;
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* 存储历史数据
|
|
123
|
+
* val [string | object]需要存储的内容
|
|
124
|
+
*/
|
|
125
|
+
setHistory(val) {
|
|
126
|
+
let searchHistory = uni.getStorageSync('search:history');
|
|
127
|
+
if (!searchHistory) searchHistory = [];
|
|
128
|
+
let serachData = {};
|
|
129
|
+
if (typeof val === 'string') {
|
|
130
|
+
serachData = {
|
|
131
|
+
adcode: [],
|
|
132
|
+
address: [],
|
|
133
|
+
city: [],
|
|
134
|
+
district: [],
|
|
135
|
+
id: [],
|
|
136
|
+
location: [],
|
|
137
|
+
name: val,
|
|
138
|
+
typecode: []
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
serachData = val;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 判断数组是否存在,如果存在,那么将放到最前面
|
|
145
|
+
for (var i = 0; i < searchHistory.length; i++) {
|
|
146
|
+
if (searchHistory[i].name === serachData.name) {
|
|
147
|
+
searchHistory.splice(i, 1);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
searchHistory.unshift(util.dataHandle(serachData));
|
|
153
|
+
uni.setStorage({
|
|
154
|
+
key: 'search:history',
|
|
155
|
+
data: searchHistory,
|
|
156
|
+
success: function () {
|
|
157
|
+
// console.log('success');
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
getHistory() {},
|
|
162
|
+
removeHistory() {
|
|
163
|
+
uni.removeStorage({
|
|
164
|
+
key: 'search:history',
|
|
165
|
+
success: function (res) {
|
|
166
|
+
console.log('success');
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export default util;
|
|
@@ -48,8 +48,11 @@
|
|
|
48
48
|
</template>
|
|
49
49
|
<script>
|
|
50
50
|
import GestureLock from './gestureLock';
|
|
51
|
+
import mpMixin from '../../libs/mixin/mpMixin.js';
|
|
52
|
+
import mixin from '../../libs/mixin/mixin.js';
|
|
51
53
|
export default {
|
|
52
|
-
|
|
54
|
+
mixins: [mpMixin, mixin],
|
|
55
|
+
name: 'cvDrawGestureLock',
|
|
53
56
|
props: {
|
|
54
57
|
/**
|
|
55
58
|
* 容器宽度
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
class GestureLock {
|
|
2
|
+
constructor(containerWidth, cycleRadius) {
|
|
3
|
+
this.containerWidth = containerWidth; // 容器宽度
|
|
4
|
+
this.cycleRadius = cycleRadius; // 圆的半径
|
|
5
|
+
|
|
6
|
+
this.circleArray = []; // 全部圆的对象数组
|
|
7
|
+
this.checkPoints = []; // 选中的圆的对象数组
|
|
8
|
+
this.lineArray = []; // 已激活锁之间的线段数组
|
|
9
|
+
this.lastCheckPoint = 0; // 最后一个激活的锁
|
|
10
|
+
this.offsetX = 0; // 容器的 X 偏移
|
|
11
|
+
this.offsetY = 0; // 容器的 Y 偏移
|
|
12
|
+
this.activeLine = {}; // 最后一个激活的锁与当前位置之间的线段
|
|
13
|
+
|
|
14
|
+
this.windowWidth = wx.getSystemInfoSync().windowWidth; // 窗口大小(用于rpx 和 px 转换)
|
|
15
|
+
|
|
16
|
+
this.initCircleArray();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 初始化 画布上的 9个圆
|
|
20
|
+
initCircleArray() {
|
|
21
|
+
const cycleMargin = (this.containerWidth - 6 * this.cycleRadius) / 6;
|
|
22
|
+
let count = 0;
|
|
23
|
+
for (let i = 0; i < 3; i++) {
|
|
24
|
+
for (let j = 0; j < 3; j++) {
|
|
25
|
+
count++;
|
|
26
|
+
this.circleArray.push({
|
|
27
|
+
count: count,
|
|
28
|
+
x: this.rpxTopx((cycleMargin + this.cycleRadius) * (j * 2 + 1)),
|
|
29
|
+
y: this.rpxTopx((cycleMargin + this.cycleRadius) * (i * 2 + 1)),
|
|
30
|
+
radius: this.rpxTopx(this.cycleRadius),
|
|
31
|
+
check: false,
|
|
32
|
+
style: {
|
|
33
|
+
left: (cycleMargin + this.cycleRadius) * (j * 2 + 1) - this.cycleRadius + 'rpx',
|
|
34
|
+
top: (cycleMargin + this.cycleRadius) * (i * 2 + 1) - this.cycleRadius + 'rpx',
|
|
35
|
+
width: this.cycleRadius * 2 + 'rpx'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onTouchStart(e) {
|
|
43
|
+
this.setOffset(e);
|
|
44
|
+
this.checkTouch({
|
|
45
|
+
x: e.touches[0].pageX - this.offsetX,
|
|
46
|
+
y: e.touches[0].pageY - this.offsetY
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
onTouchMove(e) {
|
|
51
|
+
this.moveDraw(e);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onTouchEnd(e) {
|
|
55
|
+
const checkPoints = this.checkPoints;
|
|
56
|
+
this.reset();
|
|
57
|
+
return checkPoints;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 初始化 偏移量
|
|
61
|
+
setOffset(e) {
|
|
62
|
+
this.offsetX = e.currentTarget.offsetLeft;
|
|
63
|
+
this.offsetY = e.currentTarget.offsetTop;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 检测当时 触摸位置是否位于 锁上
|
|
67
|
+
checkTouch({ x, y }) {
|
|
68
|
+
for (let i = 0; i < this.circleArray.length; i++) {
|
|
69
|
+
let point = this.circleArray[i];
|
|
70
|
+
if (this.isPointInCycle(x, y, point.x, point.y, point.radius)) {
|
|
71
|
+
if (!point.check) {
|
|
72
|
+
this.checkPoints.push(point.count);
|
|
73
|
+
if (this.lastCheckPoint != 0) {
|
|
74
|
+
// 已激活锁之间的线段
|
|
75
|
+
const line = this.drawLine(this.lastCheckPoint, point);
|
|
76
|
+
this.lineArray.push(line);
|
|
77
|
+
}
|
|
78
|
+
this.lastCheckPoint = point;
|
|
79
|
+
}
|
|
80
|
+
point.check = true;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 画线 - 返回 样式 对象
|
|
87
|
+
drawLine(start, end) {
|
|
88
|
+
const width = this.getPointDis(start.x, start.y, end.x, end.y);
|
|
89
|
+
const rotate = this.getAngle(start, end);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
activeLeft: start.x + 'px',
|
|
93
|
+
activeTop: start.y + 'px',
|
|
94
|
+
activeWidth: width + 'px',
|
|
95
|
+
activeRotate: rotate + 'deg'
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 获取 画线的 角度
|
|
100
|
+
getAngle(start, end) {
|
|
101
|
+
var diff_x = end.x - start.x,
|
|
102
|
+
diff_y = end.y - start.y;
|
|
103
|
+
if (diff_x >= 0) {
|
|
104
|
+
return (360 * Math.atan(diff_y / diff_x)) / (2 * Math.PI);
|
|
105
|
+
} else {
|
|
106
|
+
return 180 + (360 * Math.atan(diff_y / diff_x)) / (2 * Math.PI);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 判断 当前点是否位于 锁内
|
|
111
|
+
isPointInCycle(x, y, circleX, circleY, radius) {
|
|
112
|
+
return this.getPointDis(x, y, circleX, circleY) < radius ? true : false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 获取两点之间距离
|
|
116
|
+
getPointDis(ax, ay, bx, by) {
|
|
117
|
+
return Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 移动 绘制
|
|
121
|
+
moveDraw(e) {
|
|
122
|
+
// 画经过的圆
|
|
123
|
+
const x = e.touches[0].pageX - this.offsetX;
|
|
124
|
+
const y = e.touches[0].pageY - this.offsetY;
|
|
125
|
+
this.checkTouch({
|
|
126
|
+
x,
|
|
127
|
+
y
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// 画 最后一个激活的锁与当前位置之间的线段
|
|
131
|
+
this.activeLine = this.drawLine(this.lastCheckPoint, {
|
|
132
|
+
x,
|
|
133
|
+
y
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 使 画布 恢复初始状态
|
|
138
|
+
reset() {
|
|
139
|
+
this.circleArray.forEach((item) => {
|
|
140
|
+
item.check = false;
|
|
141
|
+
});
|
|
142
|
+
this.checkPoints = [];
|
|
143
|
+
this.lineArray = [];
|
|
144
|
+
this.activeLine = {};
|
|
145
|
+
this.lastCheckPoint = 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 获取 最后一个激活的锁与当前位置之间的线段
|
|
149
|
+
getActiveLine() {
|
|
150
|
+
return this.activeLine;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 获取 圆对象数组
|
|
154
|
+
getCycleArray() {
|
|
155
|
+
return this.circleArray;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 获取 已激活锁之间的线段
|
|
159
|
+
getLineArray() {
|
|
160
|
+
return this.lineArray;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 将 RPX 转换成 PX
|
|
164
|
+
rpxTopx(rpx) {
|
|
165
|
+
return (rpx / 750) * this.windowWidth;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default GestureLock;
|