Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SuperMan
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
罗超
SuperMan
Commits
d2e18dce
Commit
d2e18dce
authored
Aug 30, 2023
by
youjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
207aaf55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
71 deletions
+71
-71
travelDays.vue
src/components/LeaveGroupDownload/travelDays.vue
+71
-10
index.js
src/plug/index.js
+0
-61
No files found.
src/components/LeaveGroupDownload/travelDays.vue
View file @
d2e18dce
...
...
@@ -160,18 +160,79 @@
getImgColor
(
img
,
id
){
return
"#fff"
return
this
.
canvasImgColor
(
img
,
id
,
(
callback
)
=>
{
let
rgb
=
callback
rgb
=
rgb
.
split
(
','
)
let
rgb0
=
rgb
[
0
].
split
(
'('
)
let
arrRgb
=
[
rgb0
[
1
],
rgba
[
1
],
rgb
[
2
]]
if
(
this
.
getRgbLevel
(
arrRgb
)
>
50
){
return
"#333"
}
else
{
return
"#fff"
// this.canvasImgColor(img,id, (callback) => {
// let rgb = callback
// rgb = rgb.split(',')
// let rgb0 = rgb[0].split('(')
// let arrRgb = [rgb0[1],rgba[1],rgb[2]]
// if(this.getRgbLevel(arrRgb)>50){
// return "#333"
// }else{
// return "#fff"
// }
// })
},
// 获取图片颜色
canvasImgColor
(
imgs
,
ids
,
callback
)
{
var
imgSrc
=
imgs
var
upload
=
document
.
getElementById
(
ids
)
const
imgEle
=
document
.
createElement
(
'img'
)
const
canvas
=
document
.
createElement
(
'canvas'
)
imgEle
.
src
=
imgSrc
imgEle
.
crossOrigin
=
''
;
imgEle
.
onload
=
()
=>
{
var
ctx
=
canvas
.
getContext
(
"2d"
);
var
naturalImgSize
=
[
imgEle
.
naturalWidth
,
imgEle
.
naturalHeight
];
canvas
.
width
=
naturalImgSize
[
0
];
canvas
.
height
=
naturalImgSize
[
1
];
//绘制到canvas
ctx
.
drawImage
(
imgEle
,
0
,
0
);
//获取imageData:rgba像素点
var
imgData
=
ctx
.
getImageData
(
0
,
0
,
canvas
.
width
,
canvas
.
height
);
const
leftSectionData
=
[]
const
rightSectionData
=
[]
const
oneLineImgDataLen
=
canvas
.
width
*
4
;
imgData
.
data
.
forEach
((
colorVal
,
i
)
=>
{
if
(
i
%
oneLineImgDataLen
<=
0.5
*
oneLineImgDataLen
||
i
%
oneLineImgDataLen
>=
0.6
*
oneLineImgDataLen
)
{
const
inLeft
=
i
%
oneLineImgDataLen
<=
0.5
*
oneLineImgDataLen
if
(
i
%
4
===
0
)
{
// 获取rgb均值
const
curAverageRGB
=
(
imgData
.
data
[
i
]
+
imgData
.
data
[
i
+
1
]
+
imgData
.
data
[
i
+
2
])
/
3
;
let
leftOrRightRef
=
inLeft
?
leftSectionData
:
rightSectionData
;
//每个数组里存四个值:本颜色值中的r、g、b的均值,以及r、g、b三个值。
//均值一方面用于累加计算本区域的整体均值,然后再跟每个均值对比拿到与整体均值最接近的项的索引,再取该数组里的后三个值:rgb,对应着颜色
leftOrRightRef
[
leftOrRightRef
.
length
]
=
[
curAverageRGB
,
imgData
.
data
[
i
],
imgData
.
data
[
i
+
1
],
imgData
.
data
[
i
+
2
]]
}
}
})
//generate average rgb
const
averageOfLeft
=
Math
.
round
(
leftSectionData
.
reduce
((
_cur
,
item
)
=>
{
return
_cur
+
item
[
0
]
},
0
)
/
leftSectionData
.
length
)
const
averageOfRight
=
Math
.
round
(
rightSectionData
.
reduce
((
_cur
,
item
)
=>
{
return
_cur
+
item
[
0
]
},
0
)
/
rightSectionData
.
length
)
//find the most near color
const
findNearestIndex
=
(
averageVal
,
arrBox
)
=>
{
let
_gapValue
=
Math
.
abs
(
averageVal
-
arrBox
[
0
])
let
_nearColorIndex
=
0
arrBox
.
forEach
((
item
,
index
)
=>
{
const
curGapValue
=
Math
.
abs
(
item
-
averageVal
)
if
(
curGapValue
<
_gapValue
)
{
_gapValue
=
curGapValue
_nearColorIndex
=
index
}
})
return
_nearColorIndex
}
})
const
leftNearestColor
=
leftSectionData
[
findNearestIndex
(
averageOfLeft
,
leftSectionData
)]
const
rightNearestColor
=
rightSectionData
[
findNearestIndex
(
averageOfRight
,
rightSectionData
)]
upload
.
style
.
backgroundColor
=
`rgba(
${
leftNearestColor
[
1
]}
,
${
leftNearestColor
[
2
]}
,
${
leftNearestColor
[
3
]}
,1) 0%,rgba(
${
rightNearestColor
[
1
]}
,
${
rightNearestColor
[
2
]}
,
${
rightNearestColor
[
3
]}
,1)`
callback
(
upload
.
style
.
backgroundColor
)
}
}
},
computed
:
{},
watch
:
{
...
...
src/plug/index.js
View file @
d2e18dce
...
...
@@ -1743,67 +1743,6 @@ export default {
Vue
.
prototype
.
getRgbLevel
=
function
(
arr
)
{
return
arr
[
0
]
*
0.299
+
arr
[
1
]
*
0.587
+
arr
[
2
]
*
0.114
;
}
// 获取图片颜色
Vue
.
prototype
.
canvasImgColor
=
function
(
imgs
,
callback
)
{
var
imgSrc
=
imgs
var
upload
=
document
.
getElementById
(
'uploadImg'
)
const
imgEle
=
document
.
createElement
(
'img'
)
const
canvas
=
document
.
createElement
(
'canvas'
)
imgEle
.
src
=
imgSrc
imgEle
.
crossOrigin
=
''
;
imgEle
.
onload
=
()
=>
{
var
ctx
=
canvas
.
getContext
(
"2d"
);
var
naturalImgSize
=
[
imgEle
.
naturalWidth
,
imgEle
.
naturalHeight
];
canvas
.
width
=
naturalImgSize
[
0
];
canvas
.
height
=
naturalImgSize
[
1
];
//绘制到canvas
ctx
.
drawImage
(
imgEle
,
0
,
0
);
//获取imageData:rgba像素点
var
imgData
=
ctx
.
getImageData
(
0
,
0
,
canvas
.
width
,
canvas
.
height
);
const
leftSectionData
=
[]
const
rightSectionData
=
[]
const
oneLineImgDataLen
=
canvas
.
width
*
4
;
imgData
.
data
.
forEach
((
colorVal
,
i
)
=>
{
if
(
i
%
oneLineImgDataLen
<=
0.5
*
oneLineImgDataLen
||
i
%
oneLineImgDataLen
>=
0.6
*
oneLineImgDataLen
)
{
const
inLeft
=
i
%
oneLineImgDataLen
<=
0.5
*
oneLineImgDataLen
if
(
i
%
4
===
0
)
{
// 获取rgb均值
const
curAverageRGB
=
(
imgData
.
data
[
i
]
+
imgData
.
data
[
i
+
1
]
+
imgData
.
data
[
i
+
2
])
/
3
;
let
leftOrRightRef
=
inLeft
?
leftSectionData
:
rightSectionData
;
//每个数组里存四个值:本颜色值中的r、g、b的均值,以及r、g、b三个值。
//均值一方面用于累加计算本区域的整体均值,然后再跟每个均值对比拿到与整体均值最接近的项的索引,再取该数组里的后三个值:rgb,对应着颜色
leftOrRightRef
[
leftOrRightRef
.
length
]
=
[
curAverageRGB
,
imgData
.
data
[
i
],
imgData
.
data
[
i
+
1
],
imgData
.
data
[
i
+
2
]]
}
}
})
//generate average rgb
const
averageOfLeft
=
Math
.
round
(
leftSectionData
.
reduce
((
_cur
,
item
)
=>
{
return
_cur
+
item
[
0
]
},
0
)
/
leftSectionData
.
length
)
const
averageOfRight
=
Math
.
round
(
rightSectionData
.
reduce
((
_cur
,
item
)
=>
{
return
_cur
+
item
[
0
]
},
0
)
/
rightSectionData
.
length
)
//find the most near color
const
findNearestIndex
=
(
averageVal
,
arrBox
)
=>
{
let
_gapValue
=
Math
.
abs
(
averageVal
-
arrBox
[
0
])
let
_nearColorIndex
=
0
arrBox
.
forEach
((
item
,
index
)
=>
{
const
curGapValue
=
Math
.
abs
(
item
-
averageVal
)
if
(
curGapValue
<
_gapValue
)
{
_gapValue
=
curGapValue
_nearColorIndex
=
index
}
})
return
_nearColorIndex
}
const
leftNearestColor
=
leftSectionData
[
findNearestIndex
(
averageOfLeft
,
leftSectionData
)]
const
rightNearestColor
=
rightSectionData
[
findNearestIndex
(
averageOfRight
,
rightSectionData
)]
upload
.
style
.
backgroundColor
=
`rgba(
${
leftNearestColor
[
1
]}
,
${
leftNearestColor
[
2
]}
,
${
leftNearestColor
[
3
]}
,1) 0%,rgba(
${
rightNearestColor
[
1
]}
,
${
rightNearestColor
[
2
]}
,
${
rightNearestColor
[
3
]}
,1)`
callback
(
upload
.
style
.
backgroundColor
)
}
}
Vue
.
prototype
.
base64ToBlob
=
function
(
code
)
{
let
parts
=
code
.
split
(
";base64,"
);
let
contentType
=
parts
[
0
].
split
(
":"
)[
1
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment