chore: initial import
This commit is contained in:
15
tuniao-ui/libs/config/color.js
Normal file
15
tuniao-ui/libs/config/color.js
Normal file
@@ -0,0 +1,15 @@
|
||||
// TuniaoUI颜色值
|
||||
export default {
|
||||
mainColor: '#01BEFF',
|
||||
reverseMainColor: '#FFF00D',
|
||||
femaleColor: '#FF71D2',
|
||||
maleColor: '#82B2FF',
|
||||
mainOrange: '#FBBD12',
|
||||
bgColor: '#FFFFFF',
|
||||
spaceColor: '#F8F7F8',
|
||||
fontColor: '#080808',
|
||||
fontSubColor: '#AAAAAA',
|
||||
contentColor: '#838383',
|
||||
fontHolderColor: '#E6E6E6',
|
||||
maskBgColor: 'rgba(0, 0, 0, 0.4)',
|
||||
}
|
||||
17
tuniao-ui/libs/config/zIndex.js
Normal file
17
tuniao-ui/libs/config/zIndex.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// 各组件的z-index值
|
||||
export default {
|
||||
landsacpe: 29100,
|
||||
navbar: 29090,
|
||||
toast: 20090,
|
||||
goodsNav: 20089,
|
||||
alert: 20085,
|
||||
modal: 20080,
|
||||
popup: 20075,
|
||||
tips: 19080,
|
||||
sticky: 19075,
|
||||
indexListSticky: 19070,
|
||||
fab: 19060,
|
||||
mask: 9999,
|
||||
tableTr: 1001,
|
||||
tableTd: 1000
|
||||
}
|
||||
563
tuniao-ui/libs/css/color.scss
Normal file
563
tuniao-ui/libs/css/color.scss
Normal file
@@ -0,0 +1,563 @@
|
||||
|
||||
@mixin getColor($color: #FFFFFF, $light-color: #FFFFFF, $dark-color: #FFFFFF, $disabled-color: #FFFFFF) {
|
||||
color: $color !important;
|
||||
@if $color != #FFFFFF and $color != #000000 {
|
||||
&--light {
|
||||
color: $light-color !important;
|
||||
}
|
||||
&--dark {
|
||||
color: $dark-color !important;
|
||||
}
|
||||
&--disabled {
|
||||
color: $disabled-color !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin getBorderColor($color: #FFFFFF, $light-color: #FFFFFF, $dark-color: #FFFFFF, $disabled-color: #FFFFFF) {
|
||||
@if $color != #FFFFFF and $color != #000000 {
|
||||
&--light {
|
||||
border-color: $light-color !important;
|
||||
}
|
||||
&--dark {
|
||||
border-color: $dark-color !important;
|
||||
}
|
||||
&--disabled {
|
||||
border-color: $disabled-color !important;
|
||||
}
|
||||
}
|
||||
border-color: $color !important;
|
||||
}
|
||||
|
||||
@mixin getBackgroundColor($color: #FFFFFF, $light-color: #FFFFFF, $dark-color: #FFFFFF, $disabled-color: #FFFFFF) {
|
||||
background-color: $color !important;
|
||||
@if $color != #FFFFFF and $color != #000000 {
|
||||
color: $tn-font-color;
|
||||
&--light {
|
||||
background-color: $light-color !important;
|
||||
}
|
||||
&--dark {
|
||||
background-color: $dark-color !important;
|
||||
}
|
||||
&--disabled {
|
||||
background-color: $disabled-color !important;
|
||||
}
|
||||
}
|
||||
@else {
|
||||
color: $tn-font-color;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin getShadowColor($type: box, $color: #FFFFFF) {
|
||||
@if $type == box {
|
||||
box-shadow: 12rpx 12rpx 16rpx #{$color};
|
||||
} @else if $type == text {
|
||||
text-shadow: 6rpx 6rpx 8rpx #{$color};
|
||||
}
|
||||
}
|
||||
|
||||
@mixin getGradientColor($start-color, $end-color, $font-color: #FFFFFF) {
|
||||
background-image: repeating-linear-gradient(45deg, $start-color, $end-color);
|
||||
color: $font-color;
|
||||
|
||||
&--reverse {
|
||||
background-image: repeating-linear-gradient(-45deg, $start-color, $end-color);
|
||||
color: $font-color;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin getMainColorGradient($start-color, $start-color-light, $start-color-disabled, $end-color, $end-color-light) {
|
||||
@include getGradientColor($start-color, $end-color);
|
||||
|
||||
&--light {
|
||||
@include getGradientColor($start-color-light, $end-color-light, $start-color);
|
||||
}
|
||||
|
||||
&--single {
|
||||
@include getGradientColor($start-color, $start-color-disabled);
|
||||
}
|
||||
}
|
||||
|
||||
/* 颜色 start */
|
||||
.tn-color-red {
|
||||
@include getColor($tn-color-red, $tn-color-red-light, $tn-color-red-dark, $tn-color-red-disabled);
|
||||
}
|
||||
.tn-color-purplered {
|
||||
@include getColor($tn-color-purplered, $tn-color-purplered-light, $tn-color-purplered-dark, $tn-color-purplered-disabled);
|
||||
}
|
||||
.tn-color-purple {
|
||||
@include getColor($tn-color-purple, $tn-color-purple-light, $tn-color-purple-dark, $tn-color-purple-disabled);
|
||||
}
|
||||
.tn-color-bluepurple {
|
||||
@include getColor($tn-color-bluepurple, $tn-color-bluepurple-light, $tn-color-bluepurple-dark, $tn-color-bluepurple-disabled);
|
||||
}
|
||||
.tn-color-aquablue {
|
||||
@include getColor($tn-color-aquablue, $tn-color-aquablue-light, $tn-color-aquablue-dark, $tn-color-aquablue-disabled);
|
||||
}
|
||||
.tn-color-blue {
|
||||
@include getColor($tn-color-blue, $tn-color-blue-light, $tn-color-blue-dark, $tn-color-blue-disabled);
|
||||
}
|
||||
.tn-color-indigo {
|
||||
@include getColor($tn-color-indigo, $tn-color-indigo-light, $tn-color-indigo-dark, $tn-color-indigo-disabled);
|
||||
}
|
||||
.tn-color-cyan {
|
||||
@include getColor($tn-color-cyan, $tn-color-cyan-light, $tn-color-cyan-dark, $tn-color-cyan-disabled);
|
||||
}
|
||||
.tn-color-teal {
|
||||
@include getColor($tn-color-teal, $tn-color-teal-light, $tn-color-teal-dark, $tn-color-teal-disabled);
|
||||
}
|
||||
.tn-color-green {
|
||||
@include getColor($tn-color-green, $tn-color-green-light, $tn-color-green-dark, $tn-color-green-disabled);
|
||||
}
|
||||
.tn-color-yellowgreen {
|
||||
@include getColor($tn-color-yellowgreen, $tn-color-yellowgreen-light, $tn-color-yellowgreen-dark, $tn-color-yellowgreen-disabled);
|
||||
}
|
||||
.tn-color-lime {
|
||||
@include getColor($tn-color-lime, $tn-color-lime-light, $tn-color-lime-dark, $tn-color-lime-disabled);
|
||||
}
|
||||
.tn-color-yellow {
|
||||
@include getColor($tn-color-yellow, $tn-color-yellow-light, $tn-color-yellow-dark, $tn-color-yellow-disabled);
|
||||
}
|
||||
.tn-color-orangeyellow {
|
||||
@include getColor($tn-color-orangeyellow, $tn-color-orangeyellow-light, $tn-color-orangeyellow-dark, $tn-color-orangeyellow-disabled);
|
||||
}
|
||||
.tn-color-orange {
|
||||
@include getColor($tn-color-orange, $tn-color-orange-light, $tn-color-orange-dark, $tn-color-orange-disabled);
|
||||
}
|
||||
.tn-color-orangered {
|
||||
@include getColor($tn-color-orangered, $tn-color-orangered-light, $tn-color-orangered-dark, $tn-color-orangered-disabled);
|
||||
}
|
||||
.tn-color-brown {
|
||||
@include getColor($tn-color-brown, $tn-color-brown-light, $tn-color-brown-dark, $tn-color-brown-disabled);
|
||||
}
|
||||
.tn-color-grey {
|
||||
@include getColor($tn-color-grey, $tn-color-grey-light, $tn-color-grey-dark, $tn-color-grey-disabled);
|
||||
}
|
||||
.tn-color-gray {
|
||||
@include getColor($tn-color-gray, $tn-color-gray-light, $tn-color-gray-dark, $tn-color-gray-disabled);
|
||||
}
|
||||
.tn-color-white {
|
||||
@include getColor();
|
||||
}
|
||||
.tn-color-black {
|
||||
@include getColor(#000000);
|
||||
}
|
||||
/* 颜色 end */
|
||||
|
||||
/* 边框颜色 start */
|
||||
.tn-border-red {
|
||||
@include getBorderColor($tn-color-red, $tn-color-red-light, $tn-color-red-dark, $tn-color-red-disabled);
|
||||
}
|
||||
.tn-border-purplered {
|
||||
@include getBorderColor($tn-color-purplered, $tn-color-purplered-light, $tn-color-purplered-dark, $tn-color-purplered-disabled);
|
||||
}
|
||||
.tn-border-purple {
|
||||
@include getBorderColor($tn-color-purple, $tn-color-purple-light, $tn-color-purple-dark, $tn-color-purple-disabled);
|
||||
}
|
||||
.tn-border-bluepurple {
|
||||
@include getBorderColor($tn-color-bluepurple, $tn-color-bluepurple-light, $tn-color-bluepurple-dark, $tn-color-bluepurple-disabled);
|
||||
}
|
||||
.tn-border-aquablue {
|
||||
@include getBorderColor($tn-color-aquablue, $tn-color-aquablue-light, $tn-color-aquablue-dark, $tn-color-aquablue-disabled);
|
||||
}
|
||||
.tn-border-blue {
|
||||
@include getBorderColor($tn-color-blue, $tn-color-blue-light, $tn-color-blue-dark, $tn-color-blue-disabled);
|
||||
}
|
||||
.tn-border-indigo {
|
||||
@include getBorderColor($tn-color-indigo, $tn-color-indigo-light, $tn-color-indigo-dark, $tn-color-indigo-disabled);
|
||||
}
|
||||
.tn-border-cyan {
|
||||
@include getBorderColor($tn-color-cyan, $tn-color-cyan-light, $tn-color-cyan-dark, $tn-color-cyan-disabled);
|
||||
}
|
||||
.tn-border-teal {
|
||||
@include getBorderColor($tn-color-teal, $tn-color-teal-light, $tn-color-teal-dark, $tn-color-teal-disabled);
|
||||
}
|
||||
.tn-border-green {
|
||||
@include getBorderColor($tn-color-green, $tn-color-green-light, $tn-color-green-dark, $tn-color-green-disabled);
|
||||
}
|
||||
.tn-border-yellowgreen {
|
||||
@include getBorderColor($tn-color-yellowgreen, $tn-color-yellowgreen-light, $tn-color-yellowgreen-dark, $tn-color-yellowgreen-disabled);
|
||||
}
|
||||
.tn-border-lime {
|
||||
@include getBorderColor($tn-color-lime, $tn-color-lime-light, $tn-color-lime-dark, $tn-color-lime-disabled);
|
||||
}
|
||||
.tn-border-yellow {
|
||||
@include getBorderColor($tn-color-yellow, $tn-color-yellow-light, $tn-color-yellow-dark, $tn-color-yellow-disabled);
|
||||
}
|
||||
.tn-border-orangeyellow {
|
||||
@include getBorderColor($tn-color-orangeyellow, $tn-color-orangeyellow-light, $tn-color-orangeyellow-dark, $tn-color-orangeyellow-disabled);
|
||||
}
|
||||
.tn-border-orange {
|
||||
@include getBorderColor($tn-color-orange, $tn-color-orange-light, $tn-color-orange-dark, $tn-color-orange-disabled);
|
||||
}
|
||||
.tn-border-orangered {
|
||||
@include getBorderColor($tn-color-orangered, $tn-color-orangered-light, $tn-color-orangered-dark, $tn-color-orangered-disabled);
|
||||
}
|
||||
.tn-border-brown {
|
||||
@include getBorderColor($tn-color-brown, $tn-color-brown-light, $tn-color-brown-dark, $tn-color-brown-disabled);
|
||||
}
|
||||
.tn-border-grey {
|
||||
@include getBorderColor($tn-color-grey, $tn-color-grey-light, $tn-color-grey-dark, $tn-color-grey-disabled);
|
||||
}
|
||||
.tn-border-gray {
|
||||
@include getBorderColor($tn-color-gray, $tn-color-gray-light, $tn-color-gray-dark, $tn-color-gray-disabled);
|
||||
}
|
||||
.tn-border-white {
|
||||
@include getBorderColor();
|
||||
}
|
||||
.tn-border-black {
|
||||
@include getBorderColor(#000000);
|
||||
}
|
||||
/* 边框颜色 end */
|
||||
|
||||
/* 背景颜色 start */
|
||||
.tn-bg-red {
|
||||
@include getBackgroundColor($tn-color-red, $tn-color-red-light, $tn-color-red-dark, $tn-color-red-disabled);
|
||||
}
|
||||
.tn-bg-purplered {
|
||||
@include getBackgroundColor($tn-color-purplered, $tn-color-purplered-light, $tn-color-purplered-dark, $tn-color-purplered-disabled);
|
||||
}
|
||||
.tn-bg-purple {
|
||||
@include getBackgroundColor($tn-color-purple, $tn-color-purple-light, $tn-color-purple-dark, $tn-color-purple-disabled);
|
||||
}
|
||||
.tn-bg-bluepurple {
|
||||
@include getBackgroundColor($tn-color-bluepurple, $tn-color-bluepurple-light, $tn-color-bluepurple-dark, $tn-color-bluepurple-disabled);
|
||||
}
|
||||
.tn-bg-aquablue {
|
||||
@include getBackgroundColor($tn-color-aquablue, $tn-color-aquablue-light, $tn-color-aquablue-dark, $tn-color-aquablue-disabled);
|
||||
}
|
||||
.tn-bg-blue {
|
||||
@include getBackgroundColor($tn-color-blue, $tn-color-blue-light, $tn-color-blue-dark, $tn-color-blue-disabled);
|
||||
}
|
||||
.tn-bg-indigo {
|
||||
@include getBackgroundColor($tn-color-indigo, $tn-color-indigo-light, $tn-color-indigo-dark, $tn-color-indigo-disabled);
|
||||
}
|
||||
.tn-bg-cyan {
|
||||
@include getBackgroundColor($tn-color-cyan, $tn-color-cyan-light, $tn-color-cyan-dark, $tn-color-cyan-disabled);
|
||||
}
|
||||
.tn-bg-teal {
|
||||
@include getBackgroundColor($tn-color-teal, $tn-color-teal-light, $tn-color-teal-dark, $tn-color-teal-disabled);
|
||||
}
|
||||
.tn-bg-green {
|
||||
@include getBackgroundColor($tn-color-green, $tn-color-green-light, $tn-color-green-dark, $tn-color-green-disabled);
|
||||
}
|
||||
.tn-bg-yellowgreen {
|
||||
@include getBackgroundColor($tn-color-yellowgreen, $tn-color-yellowgreen-light, $tn-color-yellowgreen-dark, $tn-color-yellowgreen-disabled);
|
||||
}
|
||||
.tn-bg-lime {
|
||||
@include getBackgroundColor($tn-color-lime, $tn-color-lime-light, $tn-color-lime-dark, $tn-color-lime-disabled);
|
||||
}
|
||||
.tn-bg-yellow {
|
||||
@include getBackgroundColor($tn-color-yellow, $tn-color-yellow-light, $tn-color-yellow-dark, $tn-color-yellow-disabled);
|
||||
}
|
||||
.tn-bg-orangeyellow {
|
||||
@include getBackgroundColor($tn-color-orangeyellow, $tn-color-orangeyellow-light, $tn-color-orangeyellow-dark, $tn-color-orangeyellow-disabled);
|
||||
}
|
||||
.tn-bg-orange {
|
||||
@include getBackgroundColor($tn-color-orange, $tn-color-orange-light, $tn-color-orange-dark, $tn-color-orange-disabled);
|
||||
}
|
||||
.tn-bg-orangered {
|
||||
@include getBackgroundColor($tn-color-orangered, $tn-color-orangered-light, $tn-color-orangered-dark, $tn-color-orangered-disabled);
|
||||
}
|
||||
.tn-bg-brown {
|
||||
@include getBackgroundColor($tn-color-brown, $tn-color-brown-light, $tn-color-brown-dark, $tn-color-brown-disabled);
|
||||
}
|
||||
.tn-bg-grey {
|
||||
@include getBackgroundColor($tn-color-grey, $tn-color-grey-light, $tn-color-grey-dark, $tn-color-grey-disabled);
|
||||
}
|
||||
.tn-bg-gray {
|
||||
@include getBackgroundColor($tn-color-gray, $tn-color-gray-light, $tn-color-gray-dark, $tn-color-gray-disabled);
|
||||
}
|
||||
.tn-bg-white {
|
||||
@include getBackgroundColor();
|
||||
}
|
||||
.tn-bg-black {
|
||||
@include getBackgroundColor(#000000);
|
||||
}
|
||||
/* 背景颜色 end */
|
||||
|
||||
/* 阴影颜色 start */
|
||||
.tn-shadow-red {
|
||||
@include getShadowColor(box, $tn-color-red-light);
|
||||
}
|
||||
.tn-shadow-purplered {
|
||||
@include getShadowColor(box, $tn-color-purplered-light);
|
||||
}
|
||||
.tn-shadow-purple {
|
||||
@include getShadowColor(box, $tn-color-purple-light);
|
||||
}
|
||||
.tn-shadow-bluepurple {
|
||||
@include getShadowColor(box, $tn-color-bluepurple-light);
|
||||
}
|
||||
.tn-shadow-aquablue {
|
||||
@include getShadowColor(box, $tn-color-aquablue-light);
|
||||
}
|
||||
.tn-shadow-blue {
|
||||
@include getShadowColor(box, $tn-color-blue-light);
|
||||
}
|
||||
.tn-shadow-indigo {
|
||||
@include getShadowColor(box, $tn-color-indigo-light);
|
||||
}
|
||||
.tn-shadow-cyan {
|
||||
@include getShadowColor(box, $tn-color-cyan-light);
|
||||
}
|
||||
.tn-shadow-teal {
|
||||
@include getShadowColor(box, $tn-color-teal-light);
|
||||
}
|
||||
.tn-shadow-green {
|
||||
@include getShadowColor(box, $tn-color-green-light);
|
||||
}
|
||||
.tn-shadow-yellowgreen {
|
||||
@include getShadowColor(box, $tn-color-yellowgreen-light);
|
||||
}
|
||||
.tn-shadow-lime {
|
||||
@include getShadowColor(box, $tn-color-lime-light);
|
||||
}
|
||||
.tn-shadow-yellow {
|
||||
@include getShadowColor(box, $tn-color-yellow-light);
|
||||
}
|
||||
.tn-shadow-orangeyellow {
|
||||
@include getShadowColor(box, $tn-color-orangeyellow-light);
|
||||
}
|
||||
.tn-shadow-orange {
|
||||
@include getShadowColor(box, $tn-color-orange-light);
|
||||
}
|
||||
.tn-shadow-orangered {
|
||||
@include getShadowColor(box, $tn-color-orangered-light);
|
||||
}
|
||||
.tn-shadow-brown {
|
||||
@include getShadowColor(box, $tn-color-brown-light);
|
||||
}
|
||||
.tn-shadow-grey {
|
||||
@include getShadowColor(box, $tn-color-grey-light);
|
||||
}
|
||||
.tn-shadow-gray {
|
||||
@include getShadowColor(box, $tn-color-gray-light);
|
||||
}
|
||||
|
||||
.tn-text-shadow-red {
|
||||
@include getShadowColor(text, $tn-color-red-light);
|
||||
}
|
||||
.tn-text-shadow-purplered {
|
||||
@include getShadowColor(text, $tn-color-purplered-light);
|
||||
}
|
||||
.tn-text-shadow-purple {
|
||||
@include getShadowColor(text, $tn-color-purple-light);
|
||||
}
|
||||
.tn-text-shadow-bluepurple {
|
||||
@include getShadowColor(text, $tn-color-bluepurple-light);
|
||||
}
|
||||
.tn-text-shadow-aquablue {
|
||||
@include getShadowColor(text, $tn-color-aquablue-light);
|
||||
}
|
||||
.tn-text-shadow-blue {
|
||||
@include getShadowColor(text, $tn-color-blue-light);
|
||||
}
|
||||
.tn-text-shadow-indigo {
|
||||
@include getShadowColor(text, $tn-color-indigo-light);
|
||||
}
|
||||
.tn-text-shadow-cyan {
|
||||
@include getShadowColor(text, $tn-color-cyan-light);
|
||||
}
|
||||
.tn-text-shadow-teal {
|
||||
@include getShadowColor(text, $tn-color-teal-light);
|
||||
}
|
||||
.tn-text-shadow-green {
|
||||
@include getShadowColor(text, $tn-color-green-light);
|
||||
}
|
||||
.tn-text-shadow-yellowgreen {
|
||||
@include getShadowColor(text, $tn-color-yellowgreen-light);
|
||||
}
|
||||
.tn-text-shadow-lime {
|
||||
@include getShadowColor(text, $tn-color-lime-light);
|
||||
}
|
||||
.tn-text-shadow-yellow {
|
||||
@include getShadowColor(text, $tn-color-yellow-light);
|
||||
}
|
||||
.tn-text-shadow-orangeyellow {
|
||||
@include getShadowColor(text, $tn-color-orangeyellow-light);
|
||||
}
|
||||
.tn-text-shadow-orange {
|
||||
@include getShadowColor(text, $tn-color-orange-light);
|
||||
}
|
||||
.tn-text-shadow-orangered {
|
||||
@include getShadowColor(text, $tn-color-orangered-light);
|
||||
}
|
||||
.tn-text-shadow-brown {
|
||||
@include getShadowColor(text, $tn-color-brown-light);
|
||||
}
|
||||
.tn-text-shadow-grey {
|
||||
@include getShadowColor(text, $tn-color-grey-light);
|
||||
}
|
||||
.tn-text-shadow-gray {
|
||||
@include getShadowColor(text, $tn-color-gray-light);
|
||||
}
|
||||
/* 阴影颜色 end */
|
||||
|
||||
/* 主色渐变色 start */
|
||||
.tn-main-gradient-red {
|
||||
@include getMainColorGradient($tn-color-red, $tn-color-red-light, $tn-color-red-disabled, $tn-color-purplered, $tn-color-purplered-light);
|
||||
}
|
||||
.tn-main-gradient-purplered {
|
||||
@include getMainColorGradient($tn-color-purplered, $tn-color-purplered-light, $tn-color-purplered-disabled, $tn-color-purple, $tn-color-purple-light);
|
||||
}
|
||||
.tn-main-gradient-purple {
|
||||
@include getMainColorGradient($tn-color-purple, $tn-color-purple-light, $tn-color-purple-disabled, $tn-color-bluepurple, $tn-color-bluepurple-light);
|
||||
}
|
||||
.tn-main-gradient-bluepurple {
|
||||
@include getMainColorGradient($tn-color-bluepurple, $tn-color-bluepurple-light, $tn-color-bluepurple-disabled, $tn-color-aquablue, $tn-color-aquablue-light);
|
||||
}
|
||||
.tn-main-gradient-aquablue {
|
||||
@include getMainColorGradient($tn-color-aquablue, $tn-color-aquablue-light, $tn-color-aquablue-disabled, $tn-color-blue, $tn-color-blue-light);
|
||||
}
|
||||
.tn-main-gradient-blue {
|
||||
@include getMainColorGradient($tn-color-blue, $tn-color-blue-light, $tn-color-blue-disabled, $tn-color-indigo, $tn-color-indigo-light);
|
||||
}
|
||||
.tn-main-gradient-indigo {
|
||||
@include getMainColorGradient($tn-color-indigo, $tn-color-indigo-light, $tn-color-indigo-disabled, $tn-color-cyan, $tn-color-cyan-light);
|
||||
}
|
||||
.tn-main-gradient-cyan {
|
||||
@include getMainColorGradient($tn-color-cyan, $tn-color-cyan-light, $tn-color-cyan-disabled, $tn-color-teal, $tn-color-teal-light);
|
||||
}
|
||||
.tn-main-gradient-teal {
|
||||
@include getMainColorGradient($tn-color-teal, $tn-color-teal-light, $tn-color-teal-disabled, $tn-color-green, $tn-color-green-light);
|
||||
}
|
||||
.tn-main-gradient-green {
|
||||
@include getMainColorGradient($tn-color-green, $tn-color-green-light, $tn-color-green-disabled, $tn-color-yellowgreen, $tn-color-yellowgreen-light);
|
||||
}
|
||||
.tn-main-gradient-yellowgreen {
|
||||
@include getMainColorGradient($tn-color-yellowgreen, $tn-color-yellowgreen-light, $tn-color-yellowgreen-disabled, $tn-color-lime, $tn-color-lime-light);
|
||||
}
|
||||
.tn-main-gradient-lime {
|
||||
@include getMainColorGradient($tn-color-lime, $tn-color-lime-light, $tn-color-lime-disabled, $tn-color-yellow, $tn-color-yellow-light);
|
||||
}
|
||||
.tn-main-gradient-yellow {
|
||||
@include getMainColorGradient($tn-color-yellow, $tn-color-yellow-light, $tn-color-yellow-disabled, $tn-color-orangeyellow, $tn-color-orangeyellow-light);
|
||||
}
|
||||
.tn-main-gradient-orangeyellow {
|
||||
@include getMainColorGradient($tn-color-orangeyellow, $tn-color-orangeyellow-light, $tn-color-orangeyellow-disabled, $tn-color-orange, $tn-color-orange-light);
|
||||
}
|
||||
.tn-main-gradient-orange {
|
||||
@include getMainColorGradient($tn-color-orange, $tn-color-orange-light, $tn-color-orange-disabled, $tn-color-orangered, $tn-color-orangered-light);
|
||||
}
|
||||
.tn-main-gradient-orangered {
|
||||
@include getMainColorGradient($tn-color-orangered, $tn-color-orangered-light, $tn-color-orangered-disabled, $tn-color-red, $tn-color-red-light);
|
||||
}
|
||||
/* 主色渐变色 end */
|
||||
|
||||
/* 动态背景颜色 start */
|
||||
|
||||
.tn-dynamic-bg-1 {
|
||||
color: #fff;
|
||||
background: linear-gradient(45deg, #F15BB5, #9A5CE5, #01BEFF, #00F5D4);
|
||||
background-size: 500% 500%;
|
||||
animation: dynamicBg 15s ease infinite;
|
||||
}
|
||||
|
||||
@keyframes dynamicBg {
|
||||
0% {
|
||||
background-position: 0% 50%;
|
||||
}
|
||||
|
||||
50% {
|
||||
background-position: 100% 50%;
|
||||
}
|
||||
|
||||
100% {
|
||||
background-position: 0% 50%;
|
||||
}
|
||||
}
|
||||
|
||||
/* 动态背景颜色 end */
|
||||
|
||||
/* 酷炫背景颜色图片 start */
|
||||
|
||||
.tn-cool-bg-color-1 {
|
||||
@include getGradientColor($tn-cool-bg-color-1-start, $tn-cool-bg-color-1-end);
|
||||
}
|
||||
.tn-cool-bg-color-2 {
|
||||
@include getGradientColor($tn-cool-bg-color-2-start, $tn-cool-bg-color-2-end);
|
||||
}
|
||||
.tn-cool-bg-color-3 {
|
||||
@include getGradientColor($tn-cool-bg-color-3-start, $tn-cool-bg-color-3-end);
|
||||
}
|
||||
.tn-cool-bg-color-4 {
|
||||
@include getGradientColor($tn-cool-bg-color-4-start, $tn-cool-bg-color-4-end);
|
||||
}
|
||||
.tn-cool-bg-color-5 {
|
||||
@include getGradientColor($tn-cool-bg-color-5-start, $tn-cool-bg-color-5-end);
|
||||
}
|
||||
.tn-cool-bg-color-6 {
|
||||
@include getGradientColor($tn-cool-bg-color-6-start, $tn-cool-bg-color-6-end);
|
||||
}
|
||||
.tn-cool-bg-color-7 {
|
||||
@include getGradientColor($tn-cool-bg-color-7-start, $tn-cool-bg-color-7-end);
|
||||
}
|
||||
.tn-cool-bg-color-8 {
|
||||
@include getGradientColor($tn-cool-bg-color-8-start, $tn-cool-bg-color-8-end);
|
||||
}
|
||||
.tn-cool-bg-color-9 {
|
||||
@include getGradientColor($tn-cool-bg-color-9-start, $tn-cool-bg-color-9-end);
|
||||
}
|
||||
.tn-cool-bg-color-10 {
|
||||
@include getGradientColor($tn-cool-bg-color-10-start, $tn-cool-bg-color-10-end);
|
||||
}
|
||||
.tn-cool-bg-color-11 {
|
||||
@include getGradientColor($tn-cool-bg-color-11-start, $tn-cool-bg-color-11-end);
|
||||
}
|
||||
.tn-cool-bg-color-12 {
|
||||
@include getGradientColor($tn-cool-bg-color-12-start, $tn-cool-bg-color-12-end);
|
||||
}
|
||||
.tn-cool-bg-color-13 {
|
||||
@include getGradientColor($tn-cool-bg-color-13-start, $tn-cool-bg-color-13-end);
|
||||
}
|
||||
.tn-cool-bg-color-14 {
|
||||
@include getGradientColor($tn-cool-bg-color-14-start, $tn-cool-bg-color-14-end);
|
||||
}
|
||||
.tn-cool-bg-color-15 {
|
||||
@include getGradientColor($tn-cool-bg-color-15-start, $tn-cool-bg-color-15-end);
|
||||
}
|
||||
.tn-cool-bg-color-16 {
|
||||
@include getGradientColor($tn-cool-bg-color-16-start, $tn-cool-bg-color-16-end);
|
||||
}
|
||||
|
||||
.tn-cool-bg-image::after {
|
||||
content: " ";
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
border-radius: 10rpx;
|
||||
opacity: 1;
|
||||
transform: scale(1, 1);
|
||||
background-size: 100% 100%;
|
||||
background-image: inherit;
|
||||
}
|
||||
|
||||
.tn-cool-bg-image:nth-of-type(1n)::after {
|
||||
background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/1.png);
|
||||
}
|
||||
|
||||
.tn-cool-bg-image:nth-of-type(2n)::after {
|
||||
background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/2.png);
|
||||
}
|
||||
|
||||
.tn-cool-bg-image:nth-of-type(3n)::after {
|
||||
background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/3.png);
|
||||
}
|
||||
|
||||
.tn-cool-bg-image:nth-of-type(4n)::after {
|
||||
background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/4.png);
|
||||
}
|
||||
|
||||
.tn-cool-bg-image:nth-of-type(5n)::after {
|
||||
background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/5.png);
|
||||
}
|
||||
|
||||
.tn-cool-bg-image:nth-of-type(6n)::after {
|
||||
background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/6.png);
|
||||
}
|
||||
|
||||
/* 酷炫背景颜色图片 end */
|
||||
746
tuniao-ui/libs/css/main.scss
Normal file
746
tuniao-ui/libs/css/main.scss
Normal file
@@ -0,0 +1,746 @@
|
||||
$direction: top, right, bottom, left;
|
||||
|
||||
body {
|
||||
// 全局灰白效果
|
||||
// filter: grayscale(100%);
|
||||
// -webkit-filter: grayscale(100%);
|
||||
|
||||
background-color: $tn-bg-color;
|
||||
/* background-color: #ffffff; */
|
||||
font-size: 28rpx;
|
||||
color: $tn-font-color;
|
||||
font-family: Helvetica Neue, Helvetica, sans-serif;
|
||||
// 修复点击view标签的时候会有蓝色遮罩
|
||||
-webkit-tap-highlight-color: rgba(0,0,0,0);
|
||||
}
|
||||
|
||||
view,
|
||||
scroll-view,
|
||||
swiper,
|
||||
button,
|
||||
input,
|
||||
textarea,
|
||||
label,
|
||||
navigator,
|
||||
image {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
button::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.tn-round {
|
||||
border-radius: 5000rpx !important;
|
||||
}
|
||||
|
||||
.tn-radius {
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
|
||||
/* 基本样式 start */
|
||||
|
||||
.tn-width-full {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tn-height-full {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* 基本样式 end */
|
||||
|
||||
|
||||
/* 边框 start */
|
||||
|
||||
.tn-border-solid,
|
||||
.tn-border-solid-top,
|
||||
.tn-border-solid-right,
|
||||
.tn-border-solid-bottom,
|
||||
.tn-border-solid-left,
|
||||
.tn-border-solids,
|
||||
.tn-border-solids-top,
|
||||
.tn-border-solids-right,
|
||||
.tn-border-solids-bottom,
|
||||
.tn-border-solids-left,
|
||||
.tn-border-dashed,
|
||||
.tn-border-dashed-top,
|
||||
.tn-border-dashed-right,
|
||||
.tn-border-dashed-bottom,
|
||||
.tn-border-dashed-left {
|
||||
border-radius: inherit;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@for $i from 0 to length($direction) + 1 {
|
||||
@if $i == 0 {
|
||||
.tn-border-solid {
|
||||
border-width: 1rpx !important;
|
||||
border-style: solid;
|
||||
border-color: $tn-border-solid-color;
|
||||
|
||||
&.tn-bold-border {
|
||||
border-width: 6rpx !important;
|
||||
}
|
||||
}
|
||||
.tn-border-solids {
|
||||
border-width: 1rpx !important;
|
||||
border-style: solid;
|
||||
border-color: $tn-border-solids-color;
|
||||
|
||||
&.tn-bold-border {
|
||||
border-width: 6rpx !important;
|
||||
}
|
||||
}
|
||||
.tn-border-dashed {
|
||||
border-width: 1rpx !important;
|
||||
border-style: dashed;
|
||||
border-color: $tn-border-dashed-color;
|
||||
|
||||
&.tn-bold-border {
|
||||
border-width: 6rpx !important;
|
||||
}
|
||||
}
|
||||
} @else {
|
||||
.tn-border-solid-#{nth($direction, $i)} {
|
||||
border: 0rpx;
|
||||
border-#{nth($direction, $i)}-width: 1rpx !important;
|
||||
border-style: solid;
|
||||
border-color: $tn-border-solid-color;
|
||||
|
||||
&.tn-bold-border {
|
||||
border-#{nth($direction, $i)}-width: 6rpx !important;
|
||||
}
|
||||
}
|
||||
.tn-border-solids-#{nth($direction, $i)} {
|
||||
border: 0rpx;
|
||||
border-#{nth($direction, $i)}-width: 1rpx !important;
|
||||
border-style: solid;
|
||||
border-color: $tn-border-solids-color;
|
||||
|
||||
&.tn-bold-border {
|
||||
border-#{nth($direction, $i)}-width: 6rpx !important;
|
||||
}
|
||||
}
|
||||
.tn-border-dashed-#{nth($direction, $i)} {
|
||||
border: 0rpx;
|
||||
border-#{nth($direction, $i)}-width: 1rpx !important;
|
||||
border-style: dashed;
|
||||
border-color: $tn-border-dashed-color;
|
||||
|
||||
&.tn-bold-border {
|
||||
border-#{nth($direction, $i)}-width: 6rpx !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tn-none-border.tn-border-solid,
|
||||
.tn-none-border.tn-border-solid-top,
|
||||
.tn-none-border.tn-border-solid-right,
|
||||
.tn-none-border.tn-border-solid-bottom,
|
||||
.tn-none-border.tn-border-solid-left,
|
||||
.tn-none-border.tn-border-solids,
|
||||
.tn-none-border.tn-border-solids-top,
|
||||
.tn-none-border.tn-border-solids-right,
|
||||
.tn-none-border.tn-border-solids-bottom,
|
||||
.tn-none-border.tn-border-solids-left,
|
||||
.tn-none-border.tn-border-dashed,
|
||||
.tn-none-border.tn-border-dashed-top,
|
||||
.tn-none-border.tn-border-dashed-right,
|
||||
.tn-none-border.tn-border-dashed-bottom,
|
||||
.tn-none-border.tn-border-dashed-left {
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
.tn-none-border-top.tn-border-solid,
|
||||
.tn-none-border-top.tn-border-solid-top,
|
||||
.tn-none-border-top.tn-border-solid-right,
|
||||
.tn-none-border-top.tn-border-solid-bottom,
|
||||
.tn-none-border-top.tn-border-solid-left,
|
||||
.tn-none-border-top.tn-border-solids,
|
||||
.tn-none-border-top.tn-border-solids-top,
|
||||
.tn-none-border-top.tn-border-solids-right,
|
||||
.tn-none-border-top.tn-border-solids-bottom,
|
||||
.tn-none-border-top.tn-border-solids-left,
|
||||
.tn-none-border-top.tn-border-dashed,
|
||||
.tn-none-border-top.tn-border-dashed-top,
|
||||
.tn-none-border-top.tn-border-dashed-right,
|
||||
.tn-none-border-top.tn-border-dashed-bottom,
|
||||
.tn-none-border-top.tn-border-dashed-left {
|
||||
/* height: 0 !important; */
|
||||
border-top: 0 !important;
|
||||
}
|
||||
|
||||
.tn-none-border-right.tn-border-solid,
|
||||
.tn-none-border-right.tn-border-solid-top,
|
||||
.tn-none-border-right.tn-border-solid-right,
|
||||
.tn-none-border-right.tn-border-solid-bottom,
|
||||
.tn-none-border-right.tn-border-solid-left,
|
||||
.tn-none-border-right.tn-border-solids,
|
||||
.tn-none-border-right.tn-border-solids-top,
|
||||
.tn-none-border-right.tn-border-solids-right,
|
||||
.tn-none-border-right.tn-border-solids-bottom,
|
||||
.tn-none-border-right.tn-border-solids-left,
|
||||
.tn-none-border-right.tn-border-dashed,
|
||||
.tn-none-border-right.tn-border-dashed-top,
|
||||
.tn-none-border-right.tn-border-dashed-right,
|
||||
.tn-none-border-right.tn-border-dashed-bottom,
|
||||
.tn-none-border-right.tn-border-dashed-left {
|
||||
/* width: 0 !important; */
|
||||
border-right: 0 !important;
|
||||
}
|
||||
|
||||
.tn-none-border-bottom.tn-border-solid,
|
||||
.tn-none-border-bottom.tn-border-solid-top,
|
||||
.tn-none-border-bottom.tn-border-solid-right,
|
||||
.tn-none-border-bottom.tn-border-solid-bottom,
|
||||
.tn-none-border-bottom.tn-border-solid-left,
|
||||
.tn-none-border-bottom.tn-border-solids,
|
||||
.tn-none-border-bottom.tn-border-solids-top,
|
||||
.tn-none-border-bottom.tn-border-solids-right,
|
||||
.tn-none-border-bottom.tn-border-solids-bottom,
|
||||
.tn-none-border-bottom.tn-border-solids-left,
|
||||
.tn-none-border-bottom.tn-border-dashed,
|
||||
.tn-none-border-bottom.tn-border-dashed-top,
|
||||
.tn-none-border-bottom.tn-border-dashed-right,
|
||||
.tn-none-border-bottom.tn-border-dashed-bottom,
|
||||
.tn-none-border-bottom.tn-border-dashed-left {
|
||||
/* height: 0 !important; */
|
||||
border-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.tn-none-border-left.tn-border-solid,
|
||||
.tn-none-border-left.tn-border-solid-top,
|
||||
.tn-none-border-left.tn-border-solid-right,
|
||||
.tn-none-border-left.tn-border-solid-bottom,
|
||||
.tn-none-border-left.tn-border-solid-left,
|
||||
.tn-none-border-left.tn-border-solids,
|
||||
.tn-none-border-left.tn-border-solids-top,
|
||||
.tn-none-border-left.tn-border-solids-right,
|
||||
.tn-none-border-left.tn-border-solids-bottom,
|
||||
.tn-none-border-left.tn-border-solids-left,
|
||||
.tn-none-border-left.tn-border-dashed,
|
||||
.tn-none-border-left.tn-border-dashed-top,
|
||||
.tn-none-border-left.tn-border-dashed-right,
|
||||
.tn-none-border-left.tn-border-dashed-bottom,
|
||||
.tn-none-border-left.tn-border-dashed-left {
|
||||
/* width: 0 !important; */
|
||||
border-left: 0 !important;
|
||||
}
|
||||
|
||||
/* 边框 end */
|
||||
|
||||
|
||||
/* 阴影 start */
|
||||
|
||||
.tn-shadow {
|
||||
box-shadow: 6rpx 6rpx 8rpx $tn-shadow-color;
|
||||
}
|
||||
|
||||
.tn-shadow-warp {
|
||||
position: relative;
|
||||
box-shadow: 0 0 10rpx $tn-shadow-color;
|
||||
}
|
||||
|
||||
.tn-shadow-warp::before,
|
||||
.tn-shadow-warp::after {
|
||||
content: " ";
|
||||
position: absolute;
|
||||
top: 20rpx;
|
||||
bottom: 30rpx;
|
||||
left: 20rpx;
|
||||
width: 50%;
|
||||
box-shadow: 0 30rpx 20rpx $tn-box-shadow-color;
|
||||
transform: rotate(-3deg);
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.tn-shadow-warp::after {
|
||||
right: 20rpx;
|
||||
left: auto;
|
||||
transform: rotate(3deg);
|
||||
}
|
||||
|
||||
.tn-shadow-blur {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tn-shadow-blur::before {
|
||||
content: " ";
|
||||
display: block;
|
||||
background: inherit;
|
||||
filter: blur(10rpx);
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 10rpx;
|
||||
left: 10rpx;
|
||||
z-index: -1;
|
||||
opacity: 0.4;
|
||||
transform-origin: 0 0;
|
||||
border-radius: inherit;
|
||||
transform: scale(1, 1);
|
||||
}
|
||||
|
||||
/* 阴影 end */
|
||||
|
||||
|
||||
/* flex start */
|
||||
|
||||
.tn-flex {
|
||||
display: -webkit-flex;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* flex伸缩基准值 */
|
||||
.tn-flex-basic-xs {
|
||||
flex-basis: 20%;
|
||||
}
|
||||
|
||||
.tn-flex-basic-sm {
|
||||
flex-basis: 40%;
|
||||
}
|
||||
|
||||
.tn-flex-basic-md {
|
||||
flex-basis: 50%;
|
||||
}
|
||||
|
||||
.tn-flex-basic-lg {
|
||||
flex-basis: 60%;
|
||||
}
|
||||
|
||||
.tn-flex-basic-xl {
|
||||
flex-basis: 80%;
|
||||
}
|
||||
|
||||
.tn-flex-basic-full {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
/* flex布局的方向 */
|
||||
.tn-flex-direction-column {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.tn-flex-direction-row {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.tn-flex-direction-column-reverse {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
|
||||
.tn-flex-direction-row-reverse {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
/* flex容器设置换行 */
|
||||
.tn-flex-wrap {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tn-flex-nowrap {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
/* flex容器自身垂直方向对齐方式 */
|
||||
.tn-flex-center {
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.tn-flex-top {
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.tn-flex-end {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.tn-flex-stretch {
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
/* flex子元素垂直方向对齐方式 */
|
||||
.tn-flex-col-center {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tn-flex-col-top {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.tn-flex-col-bottom {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
/* flex子元素水平方向对齐方式 */
|
||||
.tn-flex-row-center {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.tn-flex-row-left {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.tn-flex-row-right {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.tn-flex-row-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.tn-flex-row-around {
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
/* flex子元素空间分配 */
|
||||
@for $i from 0 to 12 {
|
||||
.tn-flex-#{$i} {
|
||||
flex: $i;
|
||||
}
|
||||
}
|
||||
|
||||
.tn-col-12 {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tn-col-11 {
|
||||
width: 91.66666667%;
|
||||
}
|
||||
|
||||
.tn-col-10 {
|
||||
width: 83.33333333%;
|
||||
}
|
||||
|
||||
.tn-col-9 {
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
.tn-col-8 {
|
||||
width: 66.66666667%;
|
||||
}
|
||||
|
||||
.tn-col-7 {
|
||||
width: 58.33333333%;
|
||||
}
|
||||
|
||||
.tn-col-6 {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.tn-col-5 {
|
||||
width: 41.66666667%;
|
||||
}
|
||||
|
||||
.tn-col-4 {
|
||||
width: 33.33333333%;
|
||||
}
|
||||
|
||||
.tn-col-3 {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.tn-col-2 {
|
||||
width: 16.66666667%;
|
||||
}
|
||||
|
||||
.tn-col-1 {
|
||||
width: 8.33333333%;
|
||||
}
|
||||
|
||||
/* flex end */
|
||||
|
||||
/* 内边距 start */
|
||||
|
||||
@for $i from 0 to length($direction) + 1 {
|
||||
@if $i == 0 {
|
||||
.tn-no-margin {
|
||||
margin: 0;
|
||||
}
|
||||
.tn-margin-xs {
|
||||
margin: 10rpx;
|
||||
}
|
||||
.tn-margin-sm {
|
||||
margin: 20rpx;
|
||||
}
|
||||
.tn-margin-md {
|
||||
margin: 24rpx;
|
||||
}
|
||||
.tn-margin {
|
||||
margin: 30rpx;
|
||||
}
|
||||
.tn-margin-lg {
|
||||
margin: 40rpx;
|
||||
}
|
||||
.tn-margin-xl {
|
||||
margin: 50rpx;
|
||||
}
|
||||
.tn-margin-xxl {
|
||||
margin: 60rpx;
|
||||
}
|
||||
} @else {
|
||||
.tn-no-margin-#{nth($direction, $i)} {
|
||||
margin-#{nth($direction, $i)}: 0;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)}-xs {
|
||||
margin-#{nth($direction, $i)}: 10rpx;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)}-sm {
|
||||
margin-#{nth($direction, $i)}: 20rpx;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)}-md {
|
||||
margin-#{nth($direction, $i)}: 24rpx;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)} {
|
||||
margin-#{nth($direction, $i)}: 30rpx;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)}-lg {
|
||||
margin-#{nth($direction, $i)}: 40rpx;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)}-xl {
|
||||
margin-#{nth($direction, $i)}: 50rpx;
|
||||
}
|
||||
.tn-margin-#{nth($direction, $i)}-xxl {
|
||||
margin-#{nth($direction, $i)}: 60rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 内边距 end */
|
||||
|
||||
/* 外边距 start */
|
||||
|
||||
@for $i from 0 to length($direction) + 1 {
|
||||
@if $i == 0 {
|
||||
.tn-no-padding {
|
||||
padding: 0;
|
||||
}
|
||||
.tn-padding-xs {
|
||||
padding: 10rpx;
|
||||
}
|
||||
.tn-padding-sm {
|
||||
padding: 20rpx;
|
||||
}
|
||||
.tn-padding-md {
|
||||
padding: 24rpx;
|
||||
}
|
||||
.tn-padding {
|
||||
padding: 30rpx;
|
||||
}
|
||||
.tn-padding-lg {
|
||||
padding: 40rpx;
|
||||
}
|
||||
.tn-padding-xl {
|
||||
padding: 50rpx;
|
||||
}
|
||||
.tn-padding-xxl {
|
||||
padding: 60rpx;
|
||||
}
|
||||
} @else {
|
||||
.tn-no-padding-#{nth($direction, $i)} {
|
||||
padding-#{nth($direction, $i)}: 0;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)}-xs {
|
||||
padding-#{nth($direction, $i)}: 10rpx;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)}-sm {
|
||||
padding-#{nth($direction, $i)}: 20rpx;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)}-md {
|
||||
padding-#{nth($direction, $i)}: 24rpx;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)} {
|
||||
padding-#{nth($direction, $i)}: 30rpx;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)}-lg {
|
||||
padding-#{nth($direction, $i)}: 40rpx;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)}-xl {
|
||||
padding-#{nth($direction, $i)}: 50rpx;
|
||||
}
|
||||
.tn-padding-#{nth($direction, $i)}-xxl {
|
||||
padding-#{nth($direction, $i)}: 60rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 外边距 end */
|
||||
|
||||
/* float start */
|
||||
|
||||
.tn-float-left {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.tn-float-right {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.tn-clear-float {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.tn-clear-float::after,
|
||||
.tn-clear-float::before {
|
||||
content: " ";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
/* float end */
|
||||
|
||||
/* 文本 start */
|
||||
|
||||
.tn-text-xs {
|
||||
font-size: 20rpx;
|
||||
}
|
||||
|
||||
.tn-text-sm {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.tn-text-md {
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.tn-text-lg {
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.tn-text-xl {
|
||||
font-size: 36rpx;
|
||||
}
|
||||
|
||||
.tn-text-xxl {
|
||||
font-size: 40rpx;
|
||||
}
|
||||
|
||||
.tn-text-xl-xxl {
|
||||
font-size: 80rpx;
|
||||
}
|
||||
|
||||
.tn-text-xxl-xxl {
|
||||
font-size: 120rpx;
|
||||
}
|
||||
|
||||
.tn-text-upper {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.tn-text-cap {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.tn-text-lower {
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.tn-text-bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tn-text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tn-text-left {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tn-text-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.tn-text-justify {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
.tn-text-content {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.tn-text-ellipsis {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.tn-text-ellipsis-2 {
|
||||
display: -webkit-box;
|
||||
overflow: hidden;
|
||||
white-space: normal !important;
|
||||
text-overflow: ellipsis;
|
||||
word-wrap: break-word;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.tn-text-clip {
|
||||
-webkit-background-clip: text;
|
||||
color: transparent !important;
|
||||
}
|
||||
|
||||
.tn-text-break-word {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
/* 文本 end */
|
||||
|
||||
/* hover 点击效果 start */
|
||||
.tn-hover {
|
||||
opacity: 0.6;
|
||||
}
|
||||
/* hover 点击效果 end */
|
||||
|
||||
/* 去除原生button样式 start */
|
||||
.tn-button--clear-style {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
border-radius: inherit;
|
||||
color: inherit;
|
||||
}
|
||||
/* 去除原生button样式 end */
|
||||
|
||||
/* 头像组 start */
|
||||
// .tn-avatar-group {
|
||||
// direction: rtl;
|
||||
// unicode-bidi: bidi-override;
|
||||
// padding: 0 10rpx 0 40rpx;
|
||||
// display: inline-block;
|
||||
|
||||
// .tn-avatar {
|
||||
// margin-left: -30rpx !important;
|
||||
// border: 4rpx solid $tn-border-solid-color;
|
||||
// vertical-align: middle;
|
||||
|
||||
// &--sm {
|
||||
// margin-left: -20rpx !important;
|
||||
// border: 1rpx solid $tn-border-solid-color;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/* 头像组 end */
|
||||
|
||||
/* 提升H5端uni.toast()的层级,避免被tn-modal等遮盖 start */
|
||||
/* #ifdef H5 */
|
||||
uni-toast {
|
||||
z-index: 10090;
|
||||
}
|
||||
uni-toast .uni-toast {
|
||||
z-index: 10090;
|
||||
}
|
||||
/* #endif */
|
||||
/* 提升H5端uni.toast()的层级,避免被tn-modal等遮盖 end */
|
||||
|
||||
/* iPhoneX底部安全区定义 start */
|
||||
.tn-safe-area-inset-bottom {
|
||||
padding-bottom: 0;
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
/* iPhoneX底部安全区定义 end */
|
||||
35
tuniao-ui/libs/css/style.h5.scss
Normal file
35
tuniao-ui/libs/css/style.h5.scss
Normal file
@@ -0,0 +1,35 @@
|
||||
/* H5的时候,隐藏滚动条 */
|
||||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
width: 0 !important;
|
||||
height: 0 !important;
|
||||
-webkit-appearance: none;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* 双标签 start*/
|
||||
.capsule {
|
||||
display: inline-flex;
|
||||
vertical-align: middle;
|
||||
width: 20%;
|
||||
min-width: 136rpx;
|
||||
height: 45rpx;
|
||||
|
||||
.capsule-tag {
|
||||
margin: 0;
|
||||
|
||||
&:first-child {
|
||||
border-top-right-radius: 0rpx;
|
||||
border-bottom-right-radius: 0rpx;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
|
||||
&::after {
|
||||
border-top-left-radius: 0rpx;
|
||||
border-bottom-left-radius: 0rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* 双标签 end*/
|
||||
52
tuniao-ui/libs/css/style.mp.scss
Normal file
52
tuniao-ui/libs/css/style.mp.scss
Normal file
@@ -0,0 +1,52 @@
|
||||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
width: 0 !important;
|
||||
height: 0 !important;
|
||||
-webkit-appearance: none;
|
||||
background: transparent;
|
||||
}
|
||||
/* 微信小程序编译后页面有组件名的元素,特别处理 start */
|
||||
/* #ifdef MP-WEIXIN || MP-QQ */
|
||||
// 各家小程序宫格组件外层设置为100%,避免受到父元素display: flex;的影响
|
||||
|
||||
/* 双标签 start*/
|
||||
.capsule {
|
||||
display: inline-flex;
|
||||
vertical-align: middle;
|
||||
width: 20%;
|
||||
min-width: 136rpx;
|
||||
height: 45rpx;
|
||||
|
||||
tn-tag {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
|
||||
&:first-child {
|
||||
.tn-tag {
|
||||
border-top-right-radius: 0rpx;
|
||||
border-bottom-right-radius: 0rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
.tn-tag {
|
||||
&::after {
|
||||
border-top-left-radius: 0rpx;
|
||||
border-bottom-left-radius: 0rpx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/* 双标签 end*/
|
||||
|
||||
/* #endif */
|
||||
/* 微信小程序编译后页面有组件名的元素,特别处理 end */
|
||||
|
||||
/* 头条小程序编译后页面有组件名的元素,特别处理 start */
|
||||
/* #ifdef MP-TOUTIAO */
|
||||
// 各家小程序宫格组件外层设置为100%,避免受到父元素display: flex;的影响
|
||||
/* #endif */
|
||||
/* 头条小程序编译后页面有组件名的元素,特别处理 end */
|
||||
18
tuniao-ui/libs/function/$parent.js
Normal file
18
tuniao-ui/libs/function/$parent.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// 获取父组件的参数,在支付宝小程序中不支持provide/inject的写法
|
||||
// 在非H5中this.$parent可以获取到父组件,但是在H5中需要多次调用this.$parent.$parent.xxx
|
||||
// 传递默认值undefined表示查找最顶层的$parent
|
||||
export default function $parent(name = undefined) {
|
||||
let parent = this.$parent
|
||||
// 通过whle遍历,这里主要是为了H5需要多层解析
|
||||
while(parent) {
|
||||
// 父组件
|
||||
if (parent.$options && parent.$options.name !== name) {
|
||||
// 如果组件的name不相等,则继续查找
|
||||
parent = parent.$parent
|
||||
} else {
|
||||
return parent
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
22
tuniao-ui/libs/function/array.js
Normal file
22
tuniao-ui/libs/function/array.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 打乱传入的数组
|
||||
*
|
||||
* @param {Array} array 待打乱的数组
|
||||
*/
|
||||
function random(array = []) {
|
||||
return array.sort(() => Math.random() - 0.5)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为数组
|
||||
*
|
||||
* @param {Object} arr
|
||||
*/
|
||||
function isArray(arr) {
|
||||
return Object.prototype.toString.call(arr) === '[object Array]'
|
||||
}
|
||||
|
||||
export default {
|
||||
random,
|
||||
isArray
|
||||
}
|
||||
270
tuniao-ui/libs/function/color.js
Normal file
270
tuniao-ui/libs/function/color.js
Normal file
@@ -0,0 +1,270 @@
|
||||
let color = [
|
||||
'red',
|
||||
'purplered',
|
||||
'purple',
|
||||
'bluepurple',
|
||||
'aquablue',
|
||||
'blue',
|
||||
'indigo',
|
||||
'cyan',
|
||||
'teal',
|
||||
'green',
|
||||
'yellowgreen',
|
||||
'lime',
|
||||
'yellow',
|
||||
'orangeyellow',
|
||||
'orange',
|
||||
'orangered',
|
||||
'brown',
|
||||
'grey',
|
||||
'gray'
|
||||
]
|
||||
|
||||
// 酷炫颜色的数量
|
||||
const COOL_BG_COLOR_COUNT = 16
|
||||
|
||||
/**
|
||||
* 获取图鸟配色颜色列表
|
||||
*/
|
||||
function getTuniaoColorList() {
|
||||
return color
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型的随机颜色对应的类
|
||||
* @param {String} type 颜色类型
|
||||
*/
|
||||
function getRandomColorClass(type = 'bg') {
|
||||
const index = Math.floor(Math.random() * color.length)
|
||||
const colorValue = color[index]
|
||||
|
||||
return 'tn-' + type + '-' + colorValue
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获取酷炫背景对应的类
|
||||
*/
|
||||
function getRandomCoolBgClass() {
|
||||
const index = (Math.random() * COOL_BG_COLOR_COUNT) + 1
|
||||
return 'tn-cool-bg-color-' + Math.floor(index)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取内部背景颜色类
|
||||
*
|
||||
* @param {String} backgroundColor 背景颜色信息
|
||||
*/
|
||||
function getBackgroundColorInternalClass(backgroundColor = '') {
|
||||
if (!backgroundColor) return ''
|
||||
|
||||
if (['tn-bg', 'tn-dynamic-bg', 'tn-main-gradient', 'tn-cool-bg'].some(item => {
|
||||
return backgroundColor.includes(item)
|
||||
})) {
|
||||
return backgroundColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取背景颜色样式
|
||||
*
|
||||
* @param {String} backgroundColor 背景颜色信息
|
||||
*/
|
||||
function getBackgroundColorStyle(backgroundColor = '') {
|
||||
if (!backgroundColor) return ''
|
||||
|
||||
if (!backgroundColor.startsWith('tn-') || ['#', 'rgb', 'rgba'].some(item => {
|
||||
return backgroundColor.includes(item)
|
||||
})) {
|
||||
return backgroundColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取内部字体颜色类
|
||||
*
|
||||
* @param {String} fontColor 背景颜色信息
|
||||
*/
|
||||
function getFontColorInternalClass(fontColor = '') {
|
||||
if (!fontColor) return ''
|
||||
|
||||
if (['tn-color'].some(item => {
|
||||
return fontColor.includes(item)
|
||||
})) {
|
||||
return fontColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取字体颜色样式
|
||||
*
|
||||
* @param {String} fontColor 背景颜色信息
|
||||
*/
|
||||
function getFontColorStyle(fontColor = '') {
|
||||
if (!fontColor) return ''
|
||||
|
||||
if (!fontColor.startsWith('tn-') || ['#', 'rgb', 'rgba'].some(item => {
|
||||
return fontColor.includes(item)
|
||||
})) {
|
||||
return fontColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 求两个颜色之间的渐变值
|
||||
*
|
||||
* @param {String} startColor 开始颜色
|
||||
* @param {String} endColor 结束颜色
|
||||
* @param {Number} step 颜色等分的份额
|
||||
*/
|
||||
function colorGradient(startColor = 'rgb(0, 0, 0)', endColor='rgb(255, 255, 255)', step = 10) {
|
||||
let startRGB = hexToRGB(startColor, false)
|
||||
let startR = startRGB[0]
|
||||
let startG = startRGB[1]
|
||||
let startB = startRGB[2]
|
||||
|
||||
let endRGB = hexToRGB(endColor, false)
|
||||
let endR = endRGB[0]
|
||||
let endG = endRGB[1]
|
||||
let endB = endRGB[2]
|
||||
|
||||
// 求差值
|
||||
let R = (endR - startR) / step
|
||||
let G = (endG - startG) / step
|
||||
let B = (endB - startB) / step
|
||||
|
||||
let colorArr = []
|
||||
for (let i = 0; i < step; i++) {
|
||||
// 计算每一步的hex值
|
||||
let hex = rgbToHex(`rgb(${Math.round(R * i + startR)}, ${Math.round(G * i + startG)}, ${Math.round(B * i + startB)})`)
|
||||
colorArr.push(hex)
|
||||
}
|
||||
return colorArr
|
||||
}
|
||||
|
||||
/**
|
||||
* 将hex的颜色表示方式转换为rgb表示方式
|
||||
*
|
||||
* @param {String} color 颜色
|
||||
* @param {Boolean} str 是否返回字符串
|
||||
* @return {Array|String} rgb的值
|
||||
*/
|
||||
function hexToRGB(color, str = true) {
|
||||
let reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
||||
|
||||
color = color.toLowerCase()
|
||||
if (color && reg.test(color)) {
|
||||
// #000 => #000000
|
||||
if (color.length === 4) {
|
||||
let colorNew = '#'
|
||||
for (let i = 1; i < 4; i++) {
|
||||
colorNew += color.slice(i, i + 1).concat(color.slice(i, i + 1))
|
||||
}
|
||||
color = colorNew
|
||||
}
|
||||
// 处理六位的颜色值
|
||||
let colorChange = []
|
||||
for (let i = 1; i < 7; i += 2) {
|
||||
colorChange.push(parseInt("0x" + color.slice(i, i + 2)))
|
||||
}
|
||||
if (!str) {
|
||||
return colorChange
|
||||
} else {
|
||||
return `rgb(${colorChange[0]}, ${colorChange[1]}, ${colorChange[2]})`
|
||||
}
|
||||
} else if (/^(rgb|RGB)/.test(color)) {
|
||||
let arr = color.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(',')
|
||||
return arr.map(item => Number(item))
|
||||
} else {
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将rgb的颜色表示方式转换成hex表示方式
|
||||
*
|
||||
* @param {Object} rgb rgb颜色值
|
||||
*/
|
||||
function rgbToHex(rgb) {
|
||||
let reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
||||
if (/^(rgb|RGB)/.test(rgb)) {
|
||||
let color = rgb.replace(/(?:\(|\)|rgb|GRB)*/g, "").split(',')
|
||||
let strHex = '#'
|
||||
for (let i = 0; i < color.length; i++) {
|
||||
let hex = Number(color[i]).toString(16)
|
||||
// 保证每个值否是两位数
|
||||
hex = String(hex).length === 1 ? 0 + '' + hex: hex
|
||||
if (hex === '0') {
|
||||
hex += hex
|
||||
}
|
||||
strHex += hex
|
||||
}
|
||||
if (strHex.length !== 7) {
|
||||
strHex = rgb
|
||||
}
|
||||
return strHex
|
||||
} else if (reg.test(rgb)) {
|
||||
let num = rgb.replace(/#/, '').split('')
|
||||
if (num.length === 6) {
|
||||
return rgb
|
||||
} else if (num.length === 3) {
|
||||
let numHex = '#'
|
||||
for (let i = 0; i < num.length; i++) {
|
||||
numHex += (num[i] + num[i])
|
||||
}
|
||||
return numHex
|
||||
}
|
||||
} else {
|
||||
return rgb
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将传入的颜色值转换为rgba字符串
|
||||
*
|
||||
* @param {String} color 颜色
|
||||
* @param {Number} alpha 透明度
|
||||
*/
|
||||
function colorToRGBA(color, alpha = 0.3) {
|
||||
color = rgbToHex(color)
|
||||
// 十六进制颜色值的正则表达式
|
||||
let reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
||||
|
||||
color = color.toLowerCase()
|
||||
if (color && reg.test(color)) {
|
||||
// #000 => #000000
|
||||
if (color.length === 4) {
|
||||
let colorNew = '#'
|
||||
for (let i = 1; i < 4; i++) {
|
||||
colorNew += color.slice(i, i + 1).concat(color.slice(i, i + 1))
|
||||
}
|
||||
color = colorNew
|
||||
}
|
||||
// 处理六位的颜色值
|
||||
let colorChange = []
|
||||
for (let i = 1; i < 7; i += 2) {
|
||||
colorChange.push(parseInt("0x" + color.slice(i, i + 2)))
|
||||
}
|
||||
return `rgba(${colorChange[0]}, ${colorChange[1]}, ${colorChange[2]}, ${alpha})`
|
||||
} else {
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
COOL_BG_COLOR_COUNT: COOL_BG_COLOR_COUNT,
|
||||
getTuniaoColorList,
|
||||
getRandomColorClass,
|
||||
getRandomCoolBgClass,
|
||||
getBackgroundColorInternalClass,
|
||||
getBackgroundColorStyle,
|
||||
getFontColorInternalClass,
|
||||
getFontColorStyle,
|
||||
colorGradient,
|
||||
hexToRGB,
|
||||
rgbToHex,
|
||||
colorToRGBA
|
||||
}
|
||||
270
tuniao-ui/libs/function/colorUtils.js
Normal file
270
tuniao-ui/libs/function/colorUtils.js
Normal file
@@ -0,0 +1,270 @@
|
||||
let color = [
|
||||
'red',
|
||||
'purplered',
|
||||
'purple',
|
||||
'bluepurple',
|
||||
'aquablue',
|
||||
'blue',
|
||||
'indigo',
|
||||
'cyan',
|
||||
'teal',
|
||||
'green',
|
||||
'yellowgreen',
|
||||
'lime',
|
||||
'yellow',
|
||||
'orangeyellow',
|
||||
'orange',
|
||||
'orangered',
|
||||
'brown',
|
||||
'grey',
|
||||
'gray'
|
||||
]
|
||||
|
||||
// 酷炫颜色的数量
|
||||
const COOL_BG_COLOR_COUNT = 16
|
||||
|
||||
/**
|
||||
* 获取图鸟配色颜色列表
|
||||
*/
|
||||
function getTuniaoColorList() {
|
||||
return color
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型的随机颜色对应的类
|
||||
* @param {String} type 颜色类型
|
||||
*/
|
||||
function getRandomColorClass(type = 'bg') {
|
||||
const index = Math.floor(Math.random() * color.length)
|
||||
const colorValue = color[index]
|
||||
|
||||
return 'tn-' + type + '-' + colorValue
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获取酷炫背景对应的类
|
||||
*/
|
||||
function getRandomCoolBgClass() {
|
||||
const index = (Math.random() * COOL_BG_COLOR_COUNT) + 1
|
||||
return 'tn-cool-bg-color-' + Math.floor(index)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取内部背景颜色类
|
||||
*
|
||||
* @param {String} backgroundColor 背景颜色信息
|
||||
*/
|
||||
function getBackgroundColorInternalClass(backgroundColor = '') {
|
||||
if (!backgroundColor) return ''
|
||||
|
||||
if (['tn-bg', 'tn-dynamic-bg', 'tn-main-gradient', 'tn-cool-bg'].some(item => {
|
||||
return backgroundColor.includes(item)
|
||||
})) {
|
||||
return backgroundColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取背景颜色样式
|
||||
*
|
||||
* @param {String} backgroundColor 背景颜色信息
|
||||
*/
|
||||
function getBackgroundColorStyle(backgroundColor = '') {
|
||||
if (!backgroundColor) return ''
|
||||
|
||||
if (!backgroundColor.startsWith('tn-') || ['#', 'rgb', 'rgba'].some(item => {
|
||||
return backgroundColor.includes(item)
|
||||
})) {
|
||||
return backgroundColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取内部字体颜色类
|
||||
*
|
||||
* @param {String} fontColor 背景颜色信息
|
||||
*/
|
||||
function getFontColorInternalClass(fontColor = '') {
|
||||
if (!fontColor) return ''
|
||||
|
||||
if (['tn-color'].some(item => {
|
||||
return fontColor.includes(item)
|
||||
})) {
|
||||
return fontColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据传入的值获取字体颜色样式
|
||||
*
|
||||
* @param {String} fontColor 背景颜色信息
|
||||
*/
|
||||
function getFontColorStyle(fontColor = '') {
|
||||
if (!fontColor) return ''
|
||||
|
||||
if (!fontColor.startsWith('tn-') || ['#', 'rgb', 'rgba'].some(item => {
|
||||
return fontColor.includes(item)
|
||||
})) {
|
||||
return fontColor
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 求两个颜色之间的渐变值
|
||||
*
|
||||
* @param {String} startColor 开始颜色
|
||||
* @param {String} endColor 结束颜色
|
||||
* @param {Number} step 颜色等分的份额
|
||||
*/
|
||||
function colorGradient(startColor = 'rgb(0, 0, 0)', endColor='rgb(255, 255, 255)', step = 10) {
|
||||
let startRGB = hexToRGB(startColor, false)
|
||||
let startR = startRGB[0]
|
||||
let startG = startRGB[1]
|
||||
let startB = startRGB[2]
|
||||
|
||||
let endRGB = hexToRGB(endColor, false)
|
||||
let endR = endRGB[0]
|
||||
let endG = endRGB[1]
|
||||
let endB = endRGB[2]
|
||||
|
||||
// 求差值
|
||||
let R = (endR - startR) / step
|
||||
let G = (endG - startG) / step
|
||||
let B = (endB - startB) / step
|
||||
|
||||
let colorArr = []
|
||||
for (let i = 0; i < step; i++) {
|
||||
// 计算每一步的hex值
|
||||
let hex = rgbToHex(`rgb(${Math.round(R * i + startR)}, ${Math.round(G * i + startG)}, ${Math.round(B * i + startB)})`)
|
||||
colorArr.push(hex)
|
||||
}
|
||||
return colorArr
|
||||
}
|
||||
|
||||
/**
|
||||
* 将hex的颜色表示方式转换为rgb表示方式
|
||||
*
|
||||
* @param {String} color 颜色
|
||||
* @param {Boolean} str 是否返回字符串
|
||||
* @return {Array|String} rgb的值
|
||||
*/
|
||||
function hexToRGB(color, str = true) {
|
||||
let reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
||||
|
||||
color = color.toLowerCase()
|
||||
if (color && reg.test(color)) {
|
||||
// #000 => #000000
|
||||
if (color.length === 4) {
|
||||
let colorNew = '#'
|
||||
for (let i = 1; i < 4; i++) {
|
||||
colorNew += color.slice(i, i + 1).concat(color.slice(i, i + 1))
|
||||
}
|
||||
color = colorNew
|
||||
}
|
||||
// 处理六位的颜色值
|
||||
let colorChange = []
|
||||
for (let i = 1; i < 7; i += 2) {
|
||||
colorChange.push(parseInt("0x" + color.slice(i, i + 2)))
|
||||
}
|
||||
if (!str) {
|
||||
return colorChange
|
||||
} else {
|
||||
return `rgb(${colorChange[0]}, ${colorChange[1]}, ${colorChange[2]})`
|
||||
}
|
||||
} else if (/^(rgb|RGB)/.test(color)) {
|
||||
let arr = color.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(',')
|
||||
return arr.map(item => Number(item))
|
||||
} else {
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将rgb的颜色表示方式转换成hex表示方式
|
||||
*
|
||||
* @param {Object} rgb rgb颜色值
|
||||
*/
|
||||
function rgbToHex(rgb) {
|
||||
let reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
||||
if (/^(rgb|RGB)/.test(rgb)) {
|
||||
let color = rgb.replace(/(?:\(|\)|rgb|GRB)*/g, "").split(',')
|
||||
let strHex = '#'
|
||||
for (let i = 0; i < color.length; i++) {
|
||||
let hex = Number(color[i]).toString(16)
|
||||
// 保证每个值否是两位数
|
||||
hex = String(hex).length === 1 ? 0 + '' + hex: hex
|
||||
if (hex === '0') {
|
||||
hex += hex
|
||||
}
|
||||
strHex += hex
|
||||
}
|
||||
if (strHex.length !== 7) {
|
||||
strHex = rgb
|
||||
}
|
||||
return strHex
|
||||
} else if (reg.test(rgb)) {
|
||||
let num = rgb.replace(/#/, '').split('')
|
||||
if (num.length === 6) {
|
||||
return rgb
|
||||
} else if (num.length === 3) {
|
||||
let numHex = '#'
|
||||
for (let i = 0; i < num.length; i++) {
|
||||
numHex += (num[i] + num[i])
|
||||
}
|
||||
return numHex
|
||||
}
|
||||
} else {
|
||||
return rgb
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将传入的颜色值转换为rgba字符串
|
||||
*
|
||||
* @param {String} color 颜色
|
||||
* @param {Number} alpha 透明度
|
||||
*/
|
||||
function colorToRGBA(color, alpha = 0.3) {
|
||||
color = rgbToHex(color)
|
||||
// 十六进制颜色值的正则表达式
|
||||
let reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
|
||||
|
||||
color = color.toLowerCase()
|
||||
if (color && reg.test(color)) {
|
||||
// #000 => #000000
|
||||
if (color.length === 4) {
|
||||
let colorNew = '#'
|
||||
for (let i = 1; i < 4; i++) {
|
||||
colorNew += color.slice(i, i + 1).concat(color.slice(i, i + 1))
|
||||
}
|
||||
color = colorNew
|
||||
}
|
||||
// 处理六位的颜色值
|
||||
let colorChange = []
|
||||
for (let i = 1; i < 7; i += 2) {
|
||||
colorChange.push(parseInt("0x" + color.slice(i, i + 2)))
|
||||
}
|
||||
return `rgba(${colorChange[0]}, ${colorChange[1]}, ${colorChange[2]}, ${alpha})`
|
||||
} else {
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
COOL_BG_COLOR_COUNT: COOL_BG_COLOR_COUNT,
|
||||
getTuniaoColorList,
|
||||
getRandomColorClass,
|
||||
getRandomCoolBgClass,
|
||||
getBackgroundColorInternalClass,
|
||||
getBackgroundColorStyle,
|
||||
getFontColorInternalClass,
|
||||
getFontColorStyle,
|
||||
colorGradient,
|
||||
hexToRGB,
|
||||
rgbToHex,
|
||||
colorToRGBA
|
||||
}
|
||||
29
tuniao-ui/libs/function/deepClone.js
Normal file
29
tuniao-ui/libs/function/deepClone.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 判断是否为数组
|
||||
*
|
||||
* @param {Object} arr
|
||||
*/
|
||||
function isArray(arr) {
|
||||
return Object.prototype.toString.call(arr) === '[object Array]'
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度复制数据
|
||||
*
|
||||
* @param {Object} obj
|
||||
*/
|
||||
function deepClone(obj) {
|
||||
if ([null, undefined, NaN, false].includes(obj)) return obj
|
||||
if (typeof obj !== 'object' && typeof obj !== 'function') {
|
||||
return obj
|
||||
}
|
||||
var o = isArray(obj) ? [] : {}
|
||||
for (let i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
|
||||
}
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
export default deepClone
|
||||
80
tuniao-ui/libs/function/message.js
Normal file
80
tuniao-ui/libs/function/message.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import { getCurrentLanguage } from '../../../utils/i18n'
|
||||
|
||||
function getLocalizedText(zh, en) {
|
||||
return getCurrentLanguage() === 'en' ? en : zh
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出系统内置的toast
|
||||
*/
|
||||
function toast(title, mask = false, cb = null, icon = 'none', duration = 1500) {
|
||||
uni.showToast({
|
||||
title: title,
|
||||
icon: icon,
|
||||
mask: mask,
|
||||
duration: duration,
|
||||
success: () => {
|
||||
setTimeout(() => {
|
||||
cb && cb()
|
||||
}, duration)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出内置的加载框
|
||||
*/
|
||||
function loading(title) {
|
||||
uni.showLoading({
|
||||
title: title,
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出系统内置的modal
|
||||
*/
|
||||
function modal(title,
|
||||
content,
|
||||
confirmCb,
|
||||
showCancel = false,
|
||||
cancelCb = null,
|
||||
confirmText = getLocalizedText('确定', 'Confirm'),
|
||||
cancelText = getLocalizedText('取消', 'Cancel')) {
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
showCancel: showCancel,
|
||||
cancelText: cancelText,
|
||||
confirmText: confirmText,
|
||||
success: (res) => {
|
||||
if (res.cancel) {
|
||||
cancelCb && cancelCb()
|
||||
} else if (res.confirm) {
|
||||
confirmCb && confirmCb()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭系统内置toast
|
||||
*/
|
||||
function closeToast() {
|
||||
uni.hideToast()
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭系统内置的加载框
|
||||
*/
|
||||
function closeLoading() {
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
||||
export default {
|
||||
toast,
|
||||
loading,
|
||||
modal,
|
||||
closeToast,
|
||||
closeLoading
|
||||
}
|
||||
80
tuniao-ui/libs/function/messageUtils.js
Normal file
80
tuniao-ui/libs/function/messageUtils.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import { getCurrentLanguage } from '../../../utils/i18n'
|
||||
|
||||
function getLocalizedText(zh, en) {
|
||||
return getCurrentLanguage() === 'en' ? en : zh
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出系统内置的toast
|
||||
*/
|
||||
function toast(title, mask = false, cb = null, icon = 'none', duration = 1500) {
|
||||
uni.showToast({
|
||||
title: title,
|
||||
icon: icon,
|
||||
mask: mask,
|
||||
duration: duration,
|
||||
success: () => {
|
||||
setTimeout(() => {
|
||||
cb && cb()
|
||||
}, duration)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出内置的加载框
|
||||
*/
|
||||
function loading(title) {
|
||||
uni.showLoading({
|
||||
title: title,
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出系统内置的modal
|
||||
*/
|
||||
function modal(title,
|
||||
content,
|
||||
confirmCb,
|
||||
showCancel = false,
|
||||
cancelCb = null,
|
||||
confirmText = getLocalizedText('确定', 'Confirm'),
|
||||
cancelText = getLocalizedText('取消', 'Cancel')) {
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
showCancel: showCancel,
|
||||
cancelText: cancelText,
|
||||
confirmText: confirmText,
|
||||
success: (res) => {
|
||||
if (res.cancel) {
|
||||
cancelCb && cancelCb()
|
||||
} else if (res.confirm) {
|
||||
confirmCb && confirmCb()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭系统内置toast
|
||||
*/
|
||||
function closeToast() {
|
||||
uni.hideToast()
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭系统内置的加载框
|
||||
*/
|
||||
function closeLoading() {
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
||||
export default {
|
||||
toast,
|
||||
loading,
|
||||
modal,
|
||||
closeToast,
|
||||
closeLoading
|
||||
}
|
||||
128
tuniao-ui/libs/function/number.js
Normal file
128
tuniao-ui/libs/function/number.js
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* 格式化数字字符串
|
||||
* @param {String, Number} value 待格式化的字符串
|
||||
* @param {Number} digits 保留位数
|
||||
*/
|
||||
function formatNumberString(value, digits = 2) {
|
||||
let number = 0
|
||||
// 判断是什么类型
|
||||
if (typeof value === 'string') {
|
||||
number = Number(value)
|
||||
} else if (typeof value === 'number') {
|
||||
number = value
|
||||
}
|
||||
if (isNaN(number) || number === 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
let maxNumber = Math.pow(10, digits) - 1
|
||||
if (number > maxNumber) {
|
||||
return `${maxNumber}+`
|
||||
}
|
||||
|
||||
return number
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化数字字符串,往数字前添加0
|
||||
*
|
||||
* @param {Object} num 待格式化的数值
|
||||
*/
|
||||
function formatNumberAddZero(value) {
|
||||
let number = 0
|
||||
// 判断是什么类型
|
||||
if (typeof value === 'string') {
|
||||
number = Number(value)
|
||||
} else if (typeof value === 'number') {
|
||||
number = value
|
||||
}
|
||||
if (isNaN(number) || +number < 10) {
|
||||
return '0' + number
|
||||
} else {
|
||||
return String(number)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化数字,往数值后添加单位
|
||||
*
|
||||
* @param {Object} value 待格式化的数值
|
||||
* @param {Object} digits 保留位数
|
||||
*/
|
||||
function formatNumberAddPriceUnit(value, digits = 2) {
|
||||
// 数值分割点
|
||||
const unitSplit = [
|
||||
{ value: 1, symbol: ''},
|
||||
{ value: 1E3, symbol: 'K'},
|
||||
{ value: 1E4, symbol: 'W'},
|
||||
]
|
||||
|
||||
const reg = /\.0+$|(\.[0=9]*[1-9])0+$/
|
||||
|
||||
let number = 0
|
||||
// 判断是什么类型
|
||||
if (typeof value === 'string') {
|
||||
number = Number(value)
|
||||
} else if (typeof value === 'number') {
|
||||
number = value
|
||||
}
|
||||
|
||||
let i
|
||||
for (i = unitSplit.length - 1; i > 0; i--) {
|
||||
if (number >= unitSplit[i].value) break
|
||||
}
|
||||
return (number / unitSplit[i].value).toFixed(digits).replace(reg, "$1") + unitSplit[i].symbol
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数值的整数位数
|
||||
*
|
||||
* @param {Object} number 数值
|
||||
*/
|
||||
function getDigit(number) {
|
||||
let digit = -1
|
||||
while (number >= 1) {
|
||||
digit++
|
||||
number = number / 10
|
||||
}
|
||||
return digit
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定范围的随机数(返回整数)
|
||||
|
||||
* @param {Object} min 最小值
|
||||
* @param {Object} max 最大值
|
||||
*/
|
||||
function random(min, max) {
|
||||
if (min >= 0 && max > 0 && max >= min) {
|
||||
let gab = max - min
|
||||
return Math.random() * gab + min
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定范围的随机数(返回整数)
|
||||
|
||||
* @param {Object} min 最小值
|
||||
* @param {Object} max 最大值
|
||||
*/
|
||||
function randomInt(min, max) {
|
||||
if (min >= 0 && max > 0 && max >= min) {
|
||||
let gab = max - min + 1
|
||||
return Math.floor(Math.random() * gab + min)
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
formatNumberString,
|
||||
formatNumberAddZero,
|
||||
formatNumberAddPriceUnit,
|
||||
random,
|
||||
randomInt
|
||||
}
|
||||
69
tuniao-ui/libs/function/string.js
Normal file
69
tuniao-ui/libs/function/string.js
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 去掉字符串中空格
|
||||
*
|
||||
* @param {String} str 待处理的字符串
|
||||
* @param {String} type 处理类型
|
||||
*/
|
||||
function trim(str, type = 'both') {
|
||||
if (type === 'both') {
|
||||
return str.replace(/^\s+|\s+$/g, "")
|
||||
} else if (type === 'left') {
|
||||
return str.replace(/^\s*/g, "")
|
||||
} else if (type === 'right') {
|
||||
return str.replace(/(\s*$)/g, "")
|
||||
} else if (type === 'all') {
|
||||
return str.replace(/\s+/g, "")
|
||||
} else {
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取带单位的长度值
|
||||
*
|
||||
* @param {String} value 待处理的值
|
||||
* @param {String} unit 单位
|
||||
*/
|
||||
function getLengthUnitValue(value, unit = 'rpx') {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
if (/(%|px|rpx|auto)$/.test(value)) return value
|
||||
else return value + unit
|
||||
}
|
||||
|
||||
/**
|
||||
* 将驼峰命名的字符串转换为指定连接符来进行连接
|
||||
*
|
||||
* @param {Object} string 待转换的字符串
|
||||
* @param {Object} replace 进行连接的字符
|
||||
*/
|
||||
function humpConvertChar(string, replace = '_') {
|
||||
if (!string || !replace) {
|
||||
return ''
|
||||
}
|
||||
return string.replace(/([A-Z])/g, `${replace}$1`).toLowerCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* 将用指定连接符来进行连接的字符串转为驼峰命名的字符串
|
||||
*
|
||||
* @param {Object} string 待转换的字符串
|
||||
* @param {Object} replace 进行连接的字符
|
||||
*/
|
||||
function charConvertHump(string, replace = '_') {
|
||||
if (!string || !replace) {
|
||||
return ''
|
||||
}
|
||||
let reg = RegExp(replace + "(\\w)", "g")
|
||||
return string.replace(reg, function(all, letter) {
|
||||
return letter.toUpperCase()
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
trim,
|
||||
getLengthUnitValue,
|
||||
humpConvertChar,
|
||||
charConvertHump
|
||||
}
|
||||
232
tuniao-ui/libs/function/test.js
Normal file
232
tuniao-ui/libs/function/test.js
Normal file
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* 验证电子邮箱格式
|
||||
*/
|
||||
function email(value) {
|
||||
return /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/.test(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证手机格式
|
||||
*/
|
||||
function mobile(value) {
|
||||
return /^1[3-9]\d{9}$/.test(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证URL格式
|
||||
*/
|
||||
function url(value) {
|
||||
return /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=]*)?/.test(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证日期格式
|
||||
*/
|
||||
function date(value) {
|
||||
return !/Invalid|NaN/.test(new Date(value).toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证ISO类型的日期格式
|
||||
*/
|
||||
function dateISO(value) {
|
||||
return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证十进制数字
|
||||
*/
|
||||
function number(value) {
|
||||
return /^[\+-]?(\d+\.?\d*|\.\d+|\d\.\d+e\+\d+)$/.test(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证整数
|
||||
*/
|
||||
function digits(value) {
|
||||
return /^\d+$/.test(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证身份证号码
|
||||
*/
|
||||
function idCard(value) {
|
||||
return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(
|
||||
value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否车牌号
|
||||
*/
|
||||
function carNo(value) {
|
||||
// 新能源车牌
|
||||
const xreg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/;
|
||||
// 旧车牌
|
||||
const creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
|
||||
if (value.length === 7) {
|
||||
return creg.test(value);
|
||||
} else if (value.length === 8) {
|
||||
return xreg.test(value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额,只允许2位小数
|
||||
*/
|
||||
function amount(value) {
|
||||
//金额,只允许保留两位小数
|
||||
return /^[1-9]\d*(,\d{3})*(\.\d{1,2})?$|^0\.\d{1,2}$/.test(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中文
|
||||
*/
|
||||
function chinese(value) {
|
||||
let reg = /^[\u4e00-\u9fa5]+$/gi;
|
||||
return reg.test(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只能输入字母
|
||||
*/
|
||||
function letter(value) {
|
||||
return /^[a-zA-Z]*$/.test(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只能是字母或者数字
|
||||
*/
|
||||
function enOrNum(value) {
|
||||
//英文或者数字
|
||||
let reg = /^[0-9a-zA-Z]*$/g;
|
||||
return reg.test(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否包含某个值
|
||||
*/
|
||||
function contains(value, param) {
|
||||
return value.indexOf(param) >= 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证一个值范围[min, max]
|
||||
*/
|
||||
function range(value, param) {
|
||||
return value >= param[0] && value <= param[1]
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证一个长度范围[min, max]
|
||||
*/
|
||||
function rangeLength(value, param) {
|
||||
return value.length >= param[0] && value.length <= param[1]
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否固定电话
|
||||
*/
|
||||
function landline(value) {
|
||||
let reg = /^\d{3,4}-\d{7,8}(-\d{3,4})?$/;
|
||||
return reg.test(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为空
|
||||
*/
|
||||
function empty(value) {
|
||||
switch (typeof value) {
|
||||
case 'undefined':
|
||||
return true;
|
||||
case 'string':
|
||||
if (value.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
|
||||
break;
|
||||
case 'boolean':
|
||||
if (!value) return true;
|
||||
break;
|
||||
case 'number':
|
||||
if (0 === value || isNaN(value)) return true;
|
||||
break;
|
||||
case 'object':
|
||||
if (null === value || value.length === 0) return true;
|
||||
for (var i in value) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否json字符串
|
||||
*/
|
||||
function jsonString(value) {
|
||||
if (typeof value == 'string') {
|
||||
try {
|
||||
var obj = JSON.parse(value);
|
||||
if (typeof obj == 'object' && obj) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否数组
|
||||
*/
|
||||
function array(value) {
|
||||
if (typeof Array.isArray === "function") {
|
||||
return Array.isArray(value);
|
||||
} else {
|
||||
return Object.prototype.toString.call(value) === "[object Array]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否对象
|
||||
*/
|
||||
function object(value) {
|
||||
return Object.prototype.toString.call(value) === '[object Object]';
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否短信验证码
|
||||
*/
|
||||
function code(value, len = 6) {
|
||||
return new RegExp(`^\\d{${len}}$`).test(value);
|
||||
}
|
||||
|
||||
|
||||
export default {
|
||||
email,
|
||||
mobile,
|
||||
url,
|
||||
date,
|
||||
dateISO,
|
||||
number,
|
||||
digits,
|
||||
idCard,
|
||||
carNo,
|
||||
amount,
|
||||
chinese,
|
||||
letter,
|
||||
enOrNum,
|
||||
contains,
|
||||
range,
|
||||
rangeLength,
|
||||
empty,
|
||||
isEmpty: empty,
|
||||
jsonString,
|
||||
landline,
|
||||
object,
|
||||
array,
|
||||
code
|
||||
}
|
||||
44
tuniao-ui/libs/function/updateCustomBarInfo.js
Normal file
44
tuniao-ui/libs/function/updateCustomBarInfo.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 更新自定义顶部导航栏的高度
|
||||
*/
|
||||
function updateCustomBarInfo () {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getSystemInfo({
|
||||
success: (e) => {
|
||||
let statusBarHeight = 0
|
||||
let customBarHeight = 0
|
||||
// #ifndef MP
|
||||
statusBarHeight = e.statusBarHeight
|
||||
if (e.platform == 'android') {
|
||||
customBarHeight = e.statusBarHeight + 50
|
||||
} else {
|
||||
customBarHeight = e.statusBarHeight + 45
|
||||
};
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
statusBarHeight = e.statusBarHeight
|
||||
let custom = wx.getMenuButtonBoundingClientRect()
|
||||
customBarHeight = custom.bottom + ((custom.top - e.statusBarHeight) <= 4 ? (custom.top - e
|
||||
.statusBarHeight) + 4 : (custom.top - e.statusBarHeight))
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-ALIPAY
|
||||
statusBarHeight = e.statusBarHeight
|
||||
customBarHeight = e.statusBarHeight + e.titleBarHeight
|
||||
// #endif
|
||||
resolve({
|
||||
statusBarHeight,
|
||||
customBarHeight
|
||||
})
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("获取设备信息失败", err);
|
||||
reject()
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
export default updateCustomBarInfo
|
||||
41
tuniao-ui/libs/function/uuid.js
Normal file
41
tuniao-ui/libs/function/uuid.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 本算法来源于简书开源代码,详见:https://www.jianshu.com/p/fdbf293d0a85
|
||||
* 全局唯一标识符(uuid,Globally Unique Identifier),也称作 uuid(Universally Unique IDentifier)
|
||||
* 一般用于多个组件之间,给它一个唯一的标识符,或者v-for循环的时候,如果使用数组的index可能会导致更新列表出现问题
|
||||
* 最可能的情况是左滑删除item或者对某条信息流"不喜欢"并去掉它的时候,会导致组件内的数据可能出现错乱
|
||||
* v-for的时候,推荐使用后端返回的id而不是循环的index
|
||||
* @param {Number} len uuid的长度
|
||||
* @param {Boolean} firstT 将返回的首字母置为"t"
|
||||
* @param {Nubmer} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制
|
||||
*/
|
||||
function uuid(len = 32, firstT = true, radix = null) {
|
||||
let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
|
||||
let uuid = []
|
||||
radix = radix || chars.length
|
||||
|
||||
if (len) {
|
||||
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
|
||||
for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]
|
||||
} else {
|
||||
let r;
|
||||
// rfc4122标准要求返回的uuid中,某些位为固定的字符
|
||||
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
|
||||
uuid[14] = '4'
|
||||
|
||||
for (let i = 0; i < 36; i++) {
|
||||
if (!uuid[i]) {
|
||||
r = 0 | Math.random() * 16
|
||||
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]
|
||||
}
|
||||
}
|
||||
}
|
||||
// 移除第一个字符,并用t替代,因为第一个字符为数值时,该uuid不能用作id或者class
|
||||
if (firstT) {
|
||||
uuid.shift()
|
||||
return 't' + uuid.join('')
|
||||
} else {
|
||||
return uuid.join('')
|
||||
}
|
||||
}
|
||||
|
||||
export default uuid
|
||||
99
tuniao-ui/libs/luch-request/adapters/index.js
Normal file
99
tuniao-ui/libs/luch-request/adapters/index.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import buildURL from '../helpers/buildURL'
|
||||
import buildFullPath from '../core/buildFullPath'
|
||||
import settle from '../core/settle'
|
||||
import { isUndefined } from "../utils"
|
||||
|
||||
/**
|
||||
* 返回可选值存在的配置
|
||||
* @param {Array} keys - 可选值数组
|
||||
* @param {Object} config2 - 配置
|
||||
* @return {{}} - 存在的配置项
|
||||
*/
|
||||
const mergeKeys = (keys, config2) => {
|
||||
let config = {}
|
||||
keys.forEach(prop => {
|
||||
if (!isUndefined(config2[prop])) {
|
||||
config[prop] = config2[prop]
|
||||
}
|
||||
})
|
||||
return config
|
||||
}
|
||||
export default (config) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let fullPath = buildURL(buildFullPath(config.baseURL, config.url), config.params)
|
||||
const _config = {
|
||||
url: fullPath,
|
||||
header: config.header,
|
||||
complete: (response) => {
|
||||
config.fullPath = fullPath
|
||||
response.config = config
|
||||
try {
|
||||
// 对可能字符串不是json 的情况容错
|
||||
if (typeof response.data === 'string') {
|
||||
response.data = JSON.parse(response.data)
|
||||
}
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {
|
||||
}
|
||||
settle(resolve, reject, response)
|
||||
}
|
||||
}
|
||||
let requestTask
|
||||
if (config.method === 'UPLOAD') {
|
||||
delete _config.header['content-type']
|
||||
delete _config.header['Content-Type']
|
||||
let otherConfig = {
|
||||
// #ifdef MP-ALIPAY
|
||||
fileType: config.fileType,
|
||||
// #endif
|
||||
filePath: config.filePath,
|
||||
name: config.name
|
||||
}
|
||||
const optionalKeys = [
|
||||
// #ifdef APP-PLUS || H5
|
||||
'files',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'file',
|
||||
// #endif
|
||||
// #ifdef H5 || APP-PLUS
|
||||
'timeout',
|
||||
// #endif
|
||||
'formData'
|
||||
]
|
||||
requestTask = uni.uploadFile({..._config, ...otherConfig, ...mergeKeys(optionalKeys, config)})
|
||||
} else if (config.method === 'DOWNLOAD') {
|
||||
// #ifdef H5 || APP-PLUS
|
||||
if (!isUndefined(config['timeout'])) {
|
||||
_config['timeout'] = config['timeout']
|
||||
}
|
||||
// #endif
|
||||
requestTask = uni.downloadFile(_config)
|
||||
} else {
|
||||
const optionalKeys = [
|
||||
'data',
|
||||
'method',
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
'timeout',
|
||||
// #endif
|
||||
'dataType',
|
||||
// #ifndef MP-ALIPAY
|
||||
'responseType',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'sslVerify',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'withCredentials',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'firstIpv4',
|
||||
// #endif
|
||||
]
|
||||
requestTask = uni.request({..._config,...mergeKeys(optionalKeys, config)})
|
||||
}
|
||||
if (config.getTask) {
|
||||
config.getTask(requestTask, config)
|
||||
}
|
||||
})
|
||||
}
|
||||
51
tuniao-ui/libs/luch-request/core/InterceptorManager.js
Normal file
51
tuniao-ui/libs/luch-request/core/InterceptorManager.js
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict'
|
||||
|
||||
|
||||
function InterceptorManager() {
|
||||
this.handlers = []
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new interceptor to the stack
|
||||
*
|
||||
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
||||
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
||||
*
|
||||
* @return {Number} An ID used to remove interceptor later
|
||||
*/
|
||||
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
||||
this.handlers.push({
|
||||
fulfilled: fulfilled,
|
||||
rejected: rejected
|
||||
})
|
||||
return this.handlers.length - 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an interceptor from the stack
|
||||
*
|
||||
* @param {Number} id The ID that was returned by `use`
|
||||
*/
|
||||
InterceptorManager.prototype.eject = function eject(id) {
|
||||
if (this.handlers[id]) {
|
||||
this.handlers[id] = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all the registered interceptors
|
||||
*
|
||||
* This method is particularly useful for skipping over any
|
||||
* interceptors that may have become `null` calling `eject`.
|
||||
*
|
||||
* @param {Function} fn The function to call for each interceptor
|
||||
*/
|
||||
InterceptorManager.prototype.forEach = function forEach(fn) {
|
||||
this.handlers.forEach(h => {
|
||||
if (h !== null) {
|
||||
fn(h)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default InterceptorManager
|
||||
200
tuniao-ui/libs/luch-request/core/Request.js
Normal file
200
tuniao-ui/libs/luch-request/core/Request.js
Normal file
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
* @Class Request
|
||||
* @description luch-request http请求插件
|
||||
* @version 3.0.7
|
||||
* @Author lu-ch
|
||||
* @Date 2021-09-04
|
||||
* @Email webwork.s@qq.com
|
||||
* 文档: https://www.quanzhan.co/luch-request/
|
||||
* github: https://github.com/lei-mu/luch-request
|
||||
* DCloud: http://ext.dcloud.net.cn/plugin?id=392
|
||||
* HBuilderX: beat-3.0.4 alpha-3.0.4
|
||||
*/
|
||||
|
||||
|
||||
import dispatchRequest from './dispatchRequest'
|
||||
import InterceptorManager from './InterceptorManager'
|
||||
import mergeConfig from './mergeConfig'
|
||||
import defaults from './defaults'
|
||||
import { isPlainObject } from '../utils'
|
||||
import clone from '../utils/clone'
|
||||
|
||||
export default class Request {
|
||||
/**
|
||||
* @param {Object} arg - 全局配置
|
||||
* @param {String} arg.baseURL - 全局根路径
|
||||
* @param {Object} arg.header - 全局header
|
||||
* @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式
|
||||
* @param {String} arg.dataType = [json] - 全局默认的dataType
|
||||
* @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType。支付宝小程序不支持
|
||||
* @param {Object} arg.custom - 全局默认的自定义参数
|
||||
* @param {Number} arg.timeout - 全局默认的超时时间,单位 ms。默认60000。H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
||||
* @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书。默认true.仅App安卓端支持(HBuilderX 2.3.3+)
|
||||
* @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证(cookies)。默认false。仅H5支持(HBuilderX 2.6.15+)
|
||||
* @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4。默认false。仅 App-Android 支持 (HBuilderX 2.8.0+)
|
||||
* @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器。默认statusCode >= 200 && statusCode < 300
|
||||
*/
|
||||
constructor(arg = {}) {
|
||||
if (!isPlainObject(arg)) {
|
||||
arg = {}
|
||||
console.warn('设置全局参数必须接收一个Object')
|
||||
}
|
||||
this.config = clone({...defaults, ...arg})
|
||||
this.interceptors = {
|
||||
request: new InterceptorManager(),
|
||||
response: new InterceptorManager()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Function
|
||||
* @param {Request~setConfigCallback} f - 设置全局默认配置
|
||||
*/
|
||||
setConfig(f) {
|
||||
this.config = f(this.config)
|
||||
}
|
||||
|
||||
middleware(config) {
|
||||
config = mergeConfig(this.config, config)
|
||||
let chain = [dispatchRequest, undefined]
|
||||
let promise = Promise.resolve(config)
|
||||
|
||||
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
||||
chain.unshift(interceptor.fulfilled, interceptor.rejected)
|
||||
})
|
||||
|
||||
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
||||
chain.push(interceptor.fulfilled, interceptor.rejected)
|
||||
})
|
||||
|
||||
while (chain.length) {
|
||||
promise = promise.then(chain.shift(), chain.shift())
|
||||
}
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
* @Function
|
||||
* @param {Object} config - 请求配置项
|
||||
* @prop {String} options.url - 请求路径
|
||||
* @prop {Object} options.data - 请求参数
|
||||
* @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
|
||||
* @prop {Object} [options.dataType = config.dataType] - 如果设为 json,会尝试对返回的数据做一次 JSON.parse
|
||||
* @prop {Object} [options.header = config.header] - 请求header
|
||||
* @prop {Object} [options.method = config.method] - 请求方法
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
request(config = {}) {
|
||||
return this.middleware(config)
|
||||
}
|
||||
|
||||
get(url, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
method: 'GET',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
post(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'POST',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #ifndef MP-ALIPAY
|
||||
put(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'PUT',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
|
||||
delete(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'DELETE',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN
|
||||
connect(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'CONNECT',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN || MP-BAIDU
|
||||
head(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'HEAD',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU
|
||||
options(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'OPTIONS',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN
|
||||
trace(url, data, options = {}) {
|
||||
return this.middleware({
|
||||
url,
|
||||
data,
|
||||
method: 'TRACE',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
upload(url, config = {}) {
|
||||
config.url = url
|
||||
config.method = 'UPLOAD'
|
||||
return this.middleware(config)
|
||||
}
|
||||
|
||||
download(url, config = {}) {
|
||||
config.url = url
|
||||
config.method = 'DOWNLOAD'
|
||||
return this.middleware(config)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setConfig回调
|
||||
* @return {Object} - 返回操作后的config
|
||||
* @callback Request~setConfigCallback
|
||||
* @param {Object} config - 全局默认config
|
||||
*/
|
||||
20
tuniao-ui/libs/luch-request/core/buildFullPath.js
Normal file
20
tuniao-ui/libs/luch-request/core/buildFullPath.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
import isAbsoluteURL from '../helpers/isAbsoluteURL'
|
||||
import combineURLs from '../helpers/combineURLs'
|
||||
|
||||
/**
|
||||
* Creates a new URL by combining the baseURL with the requestedURL,
|
||||
* only when the requestedURL is not already an absolute URL.
|
||||
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
||||
*
|
||||
* @param {string} baseURL The base URL
|
||||
* @param {string} requestedURL Absolute or relative URL to combine
|
||||
* @returns {string} The combined full path
|
||||
*/
|
||||
export default function buildFullPath(baseURL, requestedURL) {
|
||||
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
||||
return combineURLs(baseURL, requestedURL)
|
||||
}
|
||||
return requestedURL
|
||||
}
|
||||
30
tuniao-ui/libs/luch-request/core/defaults.js
Normal file
30
tuniao-ui/libs/luch-request/core/defaults.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 默认的全局配置
|
||||
*/
|
||||
|
||||
|
||||
export default {
|
||||
baseURL: '',
|
||||
header: {},
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
// #ifndef MP-ALIPAY
|
||||
responseType: 'text',
|
||||
// #endif
|
||||
custom: {},
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
timeout: 60000,
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
sslVerify: true,
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
withCredentials: false,
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
firstIpv4: false,
|
||||
// #endif
|
||||
validateStatus: function validateStatus(status) {
|
||||
return status >= 200 && status < 300
|
||||
}
|
||||
}
|
||||
6
tuniao-ui/libs/luch-request/core/dispatchRequest.js
Normal file
6
tuniao-ui/libs/luch-request/core/dispatchRequest.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import adapter from '../adapters/index'
|
||||
|
||||
|
||||
export default (config) => {
|
||||
return adapter(config)
|
||||
}
|
||||
103
tuniao-ui/libs/luch-request/core/mergeConfig.js
Normal file
103
tuniao-ui/libs/luch-request/core/mergeConfig.js
Normal file
@@ -0,0 +1,103 @@
|
||||
import {deepMerge, isUndefined} from '../utils'
|
||||
|
||||
/**
|
||||
* 合并局部配置优先的配置,如果局部有该配置项则用局部,如果全局有该配置项则用全局
|
||||
* @param {Array} keys - 配置项
|
||||
* @param {Object} globalsConfig - 当前的全局配置
|
||||
* @param {Object} config2 - 局部配置
|
||||
* @return {{}}
|
||||
*/
|
||||
const mergeKeys = (keys, globalsConfig, config2) => {
|
||||
let config = {}
|
||||
keys.forEach(prop => {
|
||||
if (!isUndefined(config2[prop])) {
|
||||
config[prop] = config2[prop]
|
||||
} else if (!isUndefined(globalsConfig[prop])) {
|
||||
config[prop] = globalsConfig[prop]
|
||||
}
|
||||
})
|
||||
return config
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param globalsConfig - 当前实例的全局配置
|
||||
* @param config2 - 当前的局部配置
|
||||
* @return - 合并后的配置
|
||||
*/
|
||||
export default (globalsConfig, config2 = {}) => {
|
||||
const method = config2.method || globalsConfig.method || 'GET'
|
||||
let config = {
|
||||
baseURL: globalsConfig.baseURL || '',
|
||||
method: method,
|
||||
url: config2.url || '',
|
||||
params: config2.params || {},
|
||||
custom: {...(globalsConfig.custom || {}), ...(config2.custom || {})},
|
||||
header: deepMerge(globalsConfig.header || {}, config2.header || {})
|
||||
}
|
||||
const defaultToConfig2Keys = ['getTask', 'validateStatus']
|
||||
config = {...config, ...mergeKeys(defaultToConfig2Keys, globalsConfig, config2)}
|
||||
|
||||
// eslint-disable-next-line no-empty
|
||||
if (method === 'DOWNLOAD') {
|
||||
// #ifdef H5 || APP-PLUS
|
||||
if (!isUndefined(config2.timeout)) {
|
||||
config['timeout'] = config2['timeout']
|
||||
} else if (!isUndefined(globalsConfig.timeout)) {
|
||||
config['timeout'] = globalsConfig['timeout']
|
||||
}
|
||||
// #endif
|
||||
} else if (method === 'UPLOAD') {
|
||||
delete config.header['content-type']
|
||||
delete config.header['Content-Type']
|
||||
const uploadKeys = [
|
||||
// #ifdef APP-PLUS || H5
|
||||
'files',
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
'fileType',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'file',
|
||||
// #endif
|
||||
'filePath',
|
||||
'name',
|
||||
// #ifdef H5 || APP-PLUS
|
||||
'timeout',
|
||||
// #endif
|
||||
'formData',
|
||||
]
|
||||
uploadKeys.forEach(prop => {
|
||||
if (!isUndefined(config2[prop])) {
|
||||
config[prop] = config2[prop]
|
||||
}
|
||||
})
|
||||
// #ifdef H5 || APP-PLUS
|
||||
if (isUndefined(config.timeout) && !isUndefined(globalsConfig.timeout)) {
|
||||
config['timeout'] = globalsConfig['timeout']
|
||||
}
|
||||
// #endif
|
||||
} else {
|
||||
const defaultsKeys = [
|
||||
'data',
|
||||
// #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
|
||||
'timeout',
|
||||
// #endif
|
||||
'dataType',
|
||||
// #ifndef MP-ALIPAY
|
||||
'responseType',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'sslVerify',
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
'withCredentials',
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
'firstIpv4',
|
||||
// #endif
|
||||
]
|
||||
config = {...config, ...mergeKeys(defaultsKeys, globalsConfig, config2)}
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
16
tuniao-ui/libs/luch-request/core/settle.js
Normal file
16
tuniao-ui/libs/luch-request/core/settle.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Resolve or reject a Promise based on response status.
|
||||
*
|
||||
* @param {Function} resolve A function that resolves the promise.
|
||||
* @param {Function} reject A function that rejects the promise.
|
||||
* @param {object} response The response.
|
||||
*/
|
||||
export default function settle(resolve, reject, response) {
|
||||
const validateStatus = response.config.validateStatus
|
||||
const status = response.statusCode
|
||||
if (status && (!validateStatus || validateStatus(status))) {
|
||||
resolve(response)
|
||||
} else {
|
||||
reject(response)
|
||||
}
|
||||
}
|
||||
69
tuniao-ui/libs/luch-request/helpers/buildURL.js
Normal file
69
tuniao-ui/libs/luch-request/helpers/buildURL.js
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict'
|
||||
|
||||
import * as utils from './../utils'
|
||||
|
||||
function encode(val) {
|
||||
return encodeURIComponent(val).
|
||||
replace(/%40/gi, '@').
|
||||
replace(/%3A/gi, ':').
|
||||
replace(/%24/g, '$').
|
||||
replace(/%2C/gi, ',').
|
||||
replace(/%20/g, '+').
|
||||
replace(/%5B/gi, '[').
|
||||
replace(/%5D/gi, ']')
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a URL by appending params to the end
|
||||
*
|
||||
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||
* @param {object} [params] The params to be appended
|
||||
* @returns {string} The formatted url
|
||||
*/
|
||||
export default function buildURL(url, params) {
|
||||
/*eslint no-param-reassign:0*/
|
||||
if (!params) {
|
||||
return url
|
||||
}
|
||||
|
||||
var serializedParams
|
||||
if (utils.isURLSearchParams(params)) {
|
||||
serializedParams = params.toString()
|
||||
} else {
|
||||
var parts = []
|
||||
|
||||
utils.forEach(params, function serialize(val, key) {
|
||||
if (val === null || typeof val === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
if (utils.isArray(val)) {
|
||||
key = key + '[]'
|
||||
} else {
|
||||
val = [val]
|
||||
}
|
||||
|
||||
utils.forEach(val, function parseValue(v) {
|
||||
if (utils.isDate(v)) {
|
||||
v = v.toISOString()
|
||||
} else if (utils.isObject(v)) {
|
||||
v = JSON.stringify(v)
|
||||
}
|
||||
parts.push(encode(key) + '=' + encode(v))
|
||||
})
|
||||
})
|
||||
|
||||
serializedParams = parts.join('&')
|
||||
}
|
||||
|
||||
if (serializedParams) {
|
||||
var hashmarkIndex = url.indexOf('#')
|
||||
if (hashmarkIndex !== -1) {
|
||||
url = url.slice(0, hashmarkIndex)
|
||||
}
|
||||
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
14
tuniao-ui/libs/luch-request/helpers/combineURLs.js
Normal file
14
tuniao-ui/libs/luch-request/helpers/combineURLs.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Creates a new URL by combining the specified URLs
|
||||
*
|
||||
* @param {string} baseURL The base URL
|
||||
* @param {string} relativeURL The relative URL
|
||||
* @returns {string} The combined URL
|
||||
*/
|
||||
export default function combineURLs(baseURL, relativeURL) {
|
||||
return relativeURL
|
||||
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
||||
: baseURL
|
||||
}
|
||||
14
tuniao-ui/libs/luch-request/helpers/isAbsoluteURL.js
Normal file
14
tuniao-ui/libs/luch-request/helpers/isAbsoluteURL.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Determines whether the specified URL is absolute
|
||||
*
|
||||
* @param {string} url The URL to test
|
||||
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
||||
*/
|
||||
export default function isAbsoluteURL(url) {
|
||||
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||
// by any combination of letters, digits, plus, period, or hyphen.
|
||||
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url)
|
||||
}
|
||||
116
tuniao-ui/libs/luch-request/index.d.ts
vendored
Normal file
116
tuniao-ui/libs/luch-request/index.d.ts
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
type AnyObject = Record<string | number | symbol, any>
|
||||
type HttpPromise<T> = Promise<HttpResponse<T>>;
|
||||
type Tasks = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask
|
||||
export interface RequestTask {
|
||||
abort: () => void;
|
||||
offHeadersReceived: () => void;
|
||||
onHeadersReceived: () => void;
|
||||
}
|
||||
export interface HttpRequestConfig<T = Tasks> {
|
||||
/** 请求基地址 */
|
||||
baseURL?: string;
|
||||
/** 请求服务器接口地址 */
|
||||
url?: string;
|
||||
|
||||
/** 请求查询参数,自动拼接为查询字符串 */
|
||||
params?: AnyObject;
|
||||
/** 请求体参数 */
|
||||
data?: AnyObject;
|
||||
|
||||
/** 文件对应的 key */
|
||||
name?: string;
|
||||
/** HTTP 请求中其他额外的 form data */
|
||||
formData?: AnyObject;
|
||||
/** 要上传文件资源的路径。 */
|
||||
filePath?: string;
|
||||
/** 需要上传的文件列表。使用 files 时,filePath 和 name 不生效,App、H5( 2.6.15+) */
|
||||
files?: Array<{
|
||||
name?: string;
|
||||
file?: File;
|
||||
uri: string;
|
||||
}>;
|
||||
/** 要上传的文件对象,仅H5(2.6.15+)支持 */
|
||||
file?: File;
|
||||
|
||||
/** 请求头信息 */
|
||||
header?: AnyObject;
|
||||
/** 请求方式 */
|
||||
method?: "GET" | "POST" | "PUT" | "DELETE" | "CONNECT" | "HEAD" | "OPTIONS" | "TRACE" | "UPLOAD" | "DOWNLOAD";
|
||||
/** 如果设为 json,会尝试对返回的数据做一次 JSON.parse */
|
||||
dataType?: string;
|
||||
/** 设置响应的数据类型,支付宝小程序不支持 */
|
||||
responseType?: "text" | "arraybuffer";
|
||||
/** 自定义参数 */
|
||||
custom?: AnyObject;
|
||||
/** 超时时间,仅微信小程序(2.10.0)、支付宝小程序支持 */
|
||||
timeout?: number;
|
||||
/** DNS解析时优先使用ipv4,仅 App-Android 支持 (HBuilderX 2.8.0+) */
|
||||
firstIpv4?: boolean;
|
||||
/** 验证 ssl 证书 仅5+App安卓端支持(HBuilderX 2.3.3+) */
|
||||
sslVerify?: boolean;
|
||||
/** 跨域请求时是否携带凭证(cookies)仅H5支持(HBuilderX 2.6.15+) */
|
||||
withCredentials?: boolean;
|
||||
|
||||
/** 返回当前请求的task, options。请勿在此处修改options。 */
|
||||
getTask?: (task: T, options: HttpRequestConfig<T>) => void;
|
||||
/** 全局自定义验证器 */
|
||||
validateStatus?: (statusCode: number) => boolean | void;
|
||||
}
|
||||
export interface HttpResponse<T = any> {
|
||||
config: HttpRequestConfig;
|
||||
statusCode: number;
|
||||
cookies: Array<string>;
|
||||
data: T;
|
||||
errMsg: string;
|
||||
header: AnyObject;
|
||||
}
|
||||
export interface HttpUploadResponse<T = any> {
|
||||
config: HttpRequestConfig;
|
||||
statusCode: number;
|
||||
data: T;
|
||||
errMsg: string;
|
||||
}
|
||||
export interface HttpDownloadResponse extends HttpResponse {
|
||||
tempFilePath: string;
|
||||
}
|
||||
export interface HttpError {
|
||||
config: HttpRequestConfig;
|
||||
statusCode?: number;
|
||||
cookies?: Array<string>;
|
||||
data?: any;
|
||||
errMsg: string;
|
||||
header?: AnyObject;
|
||||
}
|
||||
export interface HttpInterceptorManager<V, E = V> {
|
||||
use(
|
||||
onFulfilled?: (config: V) => Promise<V> | V,
|
||||
onRejected?: (config: E) => Promise<E> | E
|
||||
): void;
|
||||
eject(id: number): void;
|
||||
}
|
||||
export abstract class HttpRequestAbstract {
|
||||
constructor(config?: HttpRequestConfig);
|
||||
config: HttpRequestConfig;
|
||||
interceptors: {
|
||||
request: HttpInterceptorManager<HttpRequestConfig, HttpRequestConfig>;
|
||||
response: HttpInterceptorManager<HttpResponse, HttpError>;
|
||||
}
|
||||
middleware<T = any>(config: HttpRequestConfig): HttpPromise<T>;
|
||||
request<T = any>(config: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
get<T = any>(url: string, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
upload<T = any>(url: string, config?: HttpRequestConfig<UniApp.UploadTask>): HttpPromise<T>;
|
||||
delete<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
head<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
post<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
put<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
connect<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
options<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
trace<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>;
|
||||
|
||||
download(url: string, config?: HttpRequestConfig<UniApp.DownloadTask>): Promise<HttpDownloadResponse>;
|
||||
|
||||
setConfig(onSend: (config: HttpRequestConfig) => HttpRequestConfig): void;
|
||||
}
|
||||
|
||||
declare class HttpRequest extends HttpRequestAbstract { }
|
||||
export default HttpRequest;
|
||||
2
tuniao-ui/libs/luch-request/index.js
Normal file
2
tuniao-ui/libs/luch-request/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import Request from './core/Request'
|
||||
export default Request
|
||||
135
tuniao-ui/libs/luch-request/utils.js
Normal file
135
tuniao-ui/libs/luch-request/utils.js
Normal file
@@ -0,0 +1,135 @@
|
||||
'use strict'
|
||||
|
||||
// utils is a library of generic helper functions non-specific to axios
|
||||
|
||||
var toString = Object.prototype.toString
|
||||
|
||||
/**
|
||||
* Determine if a value is an Array
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an Array, otherwise false
|
||||
*/
|
||||
export function isArray (val) {
|
||||
return toString.call(val) === '[object Array]'
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a value is an Object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an Object, otherwise false
|
||||
*/
|
||||
export function isObject (val) {
|
||||
return val !== null && typeof val === 'object'
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a Date
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a Date, otherwise false
|
||||
*/
|
||||
export function isDate (val) {
|
||||
return toString.call(val) === '[object Date]'
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a URLSearchParams object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
||||
*/
|
||||
export function isURLSearchParams (val) {
|
||||
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Iterate over an Array or an Object invoking a function for each item.
|
||||
*
|
||||
* If `obj` is an Array callback will be called passing
|
||||
* the value, index, and complete array for each item.
|
||||
*
|
||||
* If 'obj' is an Object callback will be called passing
|
||||
* the value, key, and complete object for each property.
|
||||
*
|
||||
* @param {Object|Array} obj The object to iterate
|
||||
* @param {Function} fn The callback to invoke for each item
|
||||
*/
|
||||
export function forEach (obj, fn) {
|
||||
// Don't bother if no value provided
|
||||
if (obj === null || typeof obj === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
// Force an array if not already something iterable
|
||||
if (typeof obj !== 'object') {
|
||||
/*eslint no-param-reassign:0*/
|
||||
obj = [obj]
|
||||
}
|
||||
|
||||
if (isArray(obj)) {
|
||||
// Iterate over array values
|
||||
for (var i = 0, l = obj.length; i < l; i++) {
|
||||
fn.call(null, obj[i], i, obj)
|
||||
}
|
||||
} else {
|
||||
// Iterate over object keys
|
||||
for (var key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
fn.call(null, obj[key], key, obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为boolean 值
|
||||
* @param val
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isBoolean(val) {
|
||||
return typeof val === 'boolean'
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为真正的对象{} new Object
|
||||
* @param {any} obj - 检测的对象
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isPlainObject(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]'
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function equal to merge with the difference being that no reference
|
||||
* to original objects is kept.
|
||||
*
|
||||
* @see merge
|
||||
* @param {Object} obj1 Object to merge
|
||||
* @returns {Object} Result of all merge properties
|
||||
*/
|
||||
export function deepMerge(/* obj1, obj2, obj3, ... */) {
|
||||
let result = {}
|
||||
function assignValue(val, key) {
|
||||
if (typeof result[key] === 'object' && typeof val === 'object') {
|
||||
result[key] = deepMerge(result[key], val)
|
||||
} else if (typeof val === 'object') {
|
||||
result[key] = deepMerge({}, val)
|
||||
} else {
|
||||
result[key] = val
|
||||
}
|
||||
}
|
||||
for (let i = 0, l = arguments.length; i < l; i++) {
|
||||
forEach(arguments[i], assignValue)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function isUndefined (val) {
|
||||
return typeof val === 'undefined'
|
||||
}
|
||||
264
tuniao-ui/libs/luch-request/utils/clone.js
Normal file
264
tuniao-ui/libs/luch-request/utils/clone.js
Normal file
@@ -0,0 +1,264 @@
|
||||
/* eslint-disable */
|
||||
var clone = (function() {
|
||||
'use strict';
|
||||
|
||||
function _instanceof(obj, type) {
|
||||
return type != null && obj instanceof type;
|
||||
}
|
||||
|
||||
var nativeMap;
|
||||
try {
|
||||
nativeMap = Map;
|
||||
} catch(_) {
|
||||
// maybe a reference error because no `Map`. Give it a dummy value that no
|
||||
// value will ever be an instanceof.
|
||||
nativeMap = function() {};
|
||||
}
|
||||
|
||||
var nativeSet;
|
||||
try {
|
||||
nativeSet = Set;
|
||||
} catch(_) {
|
||||
nativeSet = function() {};
|
||||
}
|
||||
|
||||
var nativePromise;
|
||||
try {
|
||||
nativePromise = Promise;
|
||||
} catch(_) {
|
||||
nativePromise = function() {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones (copies) an Object using deep copying.
|
||||
*
|
||||
* This function supports circular references by default, but if you are certain
|
||||
* there are no circular references in your object, you can save some CPU time
|
||||
* by calling clone(obj, false).
|
||||
*
|
||||
* Caution: if `circular` is false and `parent` contains circular references,
|
||||
* your program may enter an infinite loop and crash.
|
||||
*
|
||||
* @param `parent` - the object to be cloned
|
||||
* @param `circular` - set to true if the object to be cloned may contain
|
||||
* circular references. (optional - true by default)
|
||||
* @param `depth` - set to a number if the object is only to be cloned to
|
||||
* a particular depth. (optional - defaults to Infinity)
|
||||
* @param `prototype` - sets the prototype to be used when cloning an object.
|
||||
* (optional - defaults to parent prototype).
|
||||
* @param `includeNonEnumerable` - set to true if the non-enumerable properties
|
||||
* should be cloned as well. Non-enumerable properties on the prototype
|
||||
* chain will be ignored. (optional - false by default)
|
||||
*/
|
||||
function clone(parent, circular, depth, prototype, includeNonEnumerable) {
|
||||
if (typeof circular === 'object') {
|
||||
depth = circular.depth;
|
||||
prototype = circular.prototype;
|
||||
includeNonEnumerable = circular.includeNonEnumerable;
|
||||
circular = circular.circular;
|
||||
}
|
||||
// maintain two arrays for circular references, where corresponding parents
|
||||
// and children have the same index
|
||||
var allParents = [];
|
||||
var allChildren = [];
|
||||
|
||||
var useBuffer = typeof Buffer != 'undefined';
|
||||
|
||||
if (typeof circular == 'undefined')
|
||||
circular = true;
|
||||
|
||||
if (typeof depth == 'undefined')
|
||||
depth = Infinity;
|
||||
|
||||
// recurse this function so we don't reset allParents and allChildren
|
||||
function _clone(parent, depth) {
|
||||
// cloning null always returns null
|
||||
if (parent === null)
|
||||
return null;
|
||||
|
||||
if (depth === 0)
|
||||
return parent;
|
||||
|
||||
var child;
|
||||
var proto;
|
||||
if (typeof parent != 'object') {
|
||||
return parent;
|
||||
}
|
||||
|
||||
if (_instanceof(parent, nativeMap)) {
|
||||
child = new nativeMap();
|
||||
} else if (_instanceof(parent, nativeSet)) {
|
||||
child = new nativeSet();
|
||||
} else if (_instanceof(parent, nativePromise)) {
|
||||
child = new nativePromise(function (resolve, reject) {
|
||||
parent.then(function(value) {
|
||||
resolve(_clone(value, depth - 1));
|
||||
}, function(err) {
|
||||
reject(_clone(err, depth - 1));
|
||||
});
|
||||
});
|
||||
} else if (clone.__isArray(parent)) {
|
||||
child = [];
|
||||
} else if (clone.__isRegExp(parent)) {
|
||||
child = new RegExp(parent.source, __getRegExpFlags(parent));
|
||||
if (parent.lastIndex) child.lastIndex = parent.lastIndex;
|
||||
} else if (clone.__isDate(parent)) {
|
||||
child = new Date(parent.getTime());
|
||||
} else if (useBuffer && Buffer.isBuffer(parent)) {
|
||||
if (Buffer.from) {
|
||||
// Node.js >= 5.10.0
|
||||
child = Buffer.from(parent);
|
||||
} else {
|
||||
// Older Node.js versions
|
||||
child = new Buffer(parent.length);
|
||||
parent.copy(child);
|
||||
}
|
||||
return child;
|
||||
} else if (_instanceof(parent, Error)) {
|
||||
child = Object.create(parent);
|
||||
} else {
|
||||
if (typeof prototype == 'undefined') {
|
||||
proto = Object.getPrototypeOf(parent);
|
||||
child = Object.create(proto);
|
||||
}
|
||||
else {
|
||||
child = Object.create(prototype);
|
||||
proto = prototype;
|
||||
}
|
||||
}
|
||||
|
||||
if (circular) {
|
||||
var index = allParents.indexOf(parent);
|
||||
|
||||
if (index != -1) {
|
||||
return allChildren[index];
|
||||
}
|
||||
allParents.push(parent);
|
||||
allChildren.push(child);
|
||||
}
|
||||
|
||||
if (_instanceof(parent, nativeMap)) {
|
||||
parent.forEach(function(value, key) {
|
||||
var keyChild = _clone(key, depth - 1);
|
||||
var valueChild = _clone(value, depth - 1);
|
||||
child.set(keyChild, valueChild);
|
||||
});
|
||||
}
|
||||
if (_instanceof(parent, nativeSet)) {
|
||||
parent.forEach(function(value) {
|
||||
var entryChild = _clone(value, depth - 1);
|
||||
child.add(entryChild);
|
||||
});
|
||||
}
|
||||
|
||||
for (var i in parent) {
|
||||
var attrs = Object.getOwnPropertyDescriptor(parent, i);
|
||||
if (attrs) {
|
||||
child[i] = _clone(parent[i], depth - 1);
|
||||
}
|
||||
|
||||
try {
|
||||
var objProperty = Object.getOwnPropertyDescriptor(parent, i);
|
||||
if (objProperty.set === 'undefined') {
|
||||
// no setter defined. Skip cloning this property
|
||||
continue;
|
||||
}
|
||||
child[i] = _clone(parent[i], depth - 1);
|
||||
} catch(e){
|
||||
if (e instanceof TypeError) {
|
||||
// when in strict mode, TypeError will be thrown if child[i] property only has a getter
|
||||
// we can't do anything about this, other than inform the user that this property cannot be set.
|
||||
continue
|
||||
} else if (e instanceof ReferenceError) {
|
||||
//this may happen in non strict mode
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var symbols = Object.getOwnPropertySymbols(parent);
|
||||
for (var i = 0; i < symbols.length; i++) {
|
||||
// Don't need to worry about cloning a symbol because it is a primitive,
|
||||
// like a number or string.
|
||||
var symbol = symbols[i];
|
||||
var descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
|
||||
if (descriptor && !descriptor.enumerable && !includeNonEnumerable) {
|
||||
continue;
|
||||
}
|
||||
child[symbol] = _clone(parent[symbol], depth - 1);
|
||||
Object.defineProperty(child, symbol, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (includeNonEnumerable) {
|
||||
var allPropertyNames = Object.getOwnPropertyNames(parent);
|
||||
for (var i = 0; i < allPropertyNames.length; i++) {
|
||||
var propertyName = allPropertyNames[i];
|
||||
var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName);
|
||||
if (descriptor && descriptor.enumerable) {
|
||||
continue;
|
||||
}
|
||||
child[propertyName] = _clone(parent[propertyName], depth - 1);
|
||||
Object.defineProperty(child, propertyName, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
return _clone(parent, depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple flat clone using prototype, accepts only objects, usefull for property
|
||||
* override on FLAT configuration object (no nested props).
|
||||
*
|
||||
* USE WITH CAUTION! This may not behave as you wish if you do not know how this
|
||||
* works.
|
||||
*/
|
||||
clone.clonePrototype = function clonePrototype(parent) {
|
||||
if (parent === null)
|
||||
return null;
|
||||
|
||||
var c = function () {};
|
||||
c.prototype = parent;
|
||||
return new c();
|
||||
};
|
||||
|
||||
// private utility functions
|
||||
|
||||
function __objToStr(o) {
|
||||
return Object.prototype.toString.call(o);
|
||||
}
|
||||
clone.__objToStr = __objToStr;
|
||||
|
||||
function __isDate(o) {
|
||||
return typeof o === 'object' && __objToStr(o) === '[object Date]';
|
||||
}
|
||||
clone.__isDate = __isDate;
|
||||
|
||||
function __isArray(o) {
|
||||
return typeof o === 'object' && __objToStr(o) === '[object Array]';
|
||||
}
|
||||
clone.__isArray = __isArray;
|
||||
|
||||
function __isRegExp(o) {
|
||||
return typeof o === 'object' && __objToStr(o) === '[object RegExp]';
|
||||
}
|
||||
clone.__isRegExp = __isRegExp;
|
||||
|
||||
function __getRegExpFlags(re) {
|
||||
var flags = '';
|
||||
if (re.global) flags += 'g';
|
||||
if (re.ignoreCase) flags += 'i';
|
||||
if (re.multiline) flags += 'm';
|
||||
return flags;
|
||||
}
|
||||
clone.__getRegExpFlags = __getRegExpFlags;
|
||||
|
||||
return clone;
|
||||
})();
|
||||
|
||||
export default clone
|
||||
47
tuniao-ui/libs/mixin/components_color.js
Normal file
47
tuniao-ui/libs/mixin/components_color.js
Normal file
@@ -0,0 +1,47 @@
|
||||
module.exports = {
|
||||
data() {
|
||||
|
||||
},
|
||||
props: {
|
||||
// 背景颜色
|
||||
backgroundColor: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
// 字体颜色
|
||||
fontColor: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
// 字体大小
|
||||
fontSize: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
// 字体大小单位
|
||||
fontUnit: {
|
||||
type: String,
|
||||
default: 'rpx'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
backgroundColorStyle() {
|
||||
return this.$t.color.getBackgroundColorStyle(this.backgroundColor)
|
||||
},
|
||||
backgroundColorClass() {
|
||||
return this.$t.color.getBackgroundColorInternalClass(this.backgroundColor)
|
||||
},
|
||||
fontColorStyle() {
|
||||
return this.$t.color.getFontColorStyle(this.fontColor)
|
||||
},
|
||||
fontColorClass() {
|
||||
return this.$t.color.getFontColorInternalClass(this.fontColor)
|
||||
},
|
||||
fontSizeStyle() {
|
||||
return this.$t.string.getLengthUnitValue(this.fontSize, this.fontUnit)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
68
tuniao-ui/libs/mixin/mixin.js
Normal file
68
tuniao-ui/libs/mixin/mixin.js
Normal file
@@ -0,0 +1,68 @@
|
||||
module.exports = {
|
||||
data() {
|
||||
return {}
|
||||
},
|
||||
onLoad() {
|
||||
// getRect挂载再$t上,用为这个方法需要使用in(this),所以无法把它独立层一个单独的文件导出
|
||||
this.$t.getRect = this._tGetRect
|
||||
},
|
||||
beforeDestory() {
|
||||
// 判断当前页面是否存在parent和children
|
||||
// 组件销毁时,移除子组件在父组件children数组中的实例,释放资源,避免数据混乱
|
||||
if (this.parent && uni.$t.test.array(this.parent.children)) {
|
||||
// 组件销毁时,移除子组件在父组件children数组中的实例
|
||||
const childrenList = this.parent.children
|
||||
childrenList.map((child, index) => {
|
||||
// 如果相对,则移除
|
||||
if (child === this) {
|
||||
childrenList.splice(index, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 查询节点信息
|
||||
* 当前方法在支付宝小程序中无法获取组件跟接点的尺寸
|
||||
* 解决办法:为组件根部再套一个没有任何作用的view元素
|
||||
*/
|
||||
_tGetRect(selector, all) {
|
||||
return new Promise((resolve) => {
|
||||
uni.createSelectorQuery()
|
||||
.in(this)[all ? 'selectAll' : 'select'](selector)
|
||||
.boundingClientRect(rect => {
|
||||
if (all && Array.isArray(rect) && rect.length) {
|
||||
resolve(rect)
|
||||
}
|
||||
if (!all && rect) {
|
||||
resolve(rect)
|
||||
}
|
||||
})
|
||||
.exec()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取父组件的数据
|
||||
*/
|
||||
getParentData(parentName = '') {
|
||||
// 避免再created中定义parent变量
|
||||
if (!this.parent) this.parent = false
|
||||
// 通过获取父组件实例
|
||||
// 将父组件this中对应的参数,赋值给本组件的parentData对象中对应的属性
|
||||
// 头条小程序不支持通过this.parent.xxx去监听父组件参数的变化,所以需要本方法进行实现
|
||||
this.parent = this.$t.$parent.call(this, parentName)
|
||||
if (this.parent) {
|
||||
// 遍历parentData中的属性,将parent中同名的属性赋值给parentData
|
||||
Object.keys(this.parentData).map(key => {
|
||||
this.parentData[key] = this.parent[key]
|
||||
})
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 阻止事件冒泡
|
||||
*/
|
||||
preventEvent(e) {
|
||||
e && e.stopPropagation && e.stopPropagation()
|
||||
}
|
||||
}
|
||||
}
|
||||
30
tuniao-ui/libs/mixin/mpShare.js
Normal file
30
tuniao-ui/libs/mixin/mpShare.js
Normal file
@@ -0,0 +1,30 @@
|
||||
module.exports = {
|
||||
onLoad() {
|
||||
// 设置默认的转发参数
|
||||
this.$t.mpShare = {
|
||||
// 分享的标题,默认为小程序名称
|
||||
title: '',
|
||||
// 分享的路径,默认为当前页面
|
||||
path: '',
|
||||
// 分享时显示的图片,默认为当前页面截图
|
||||
imageUrl: '',
|
||||
// 当前页面是否可以分享
|
||||
share: true
|
||||
}
|
||||
if (!this.$t.mpShare.share) {
|
||||
uni.hideShareMenu()
|
||||
}
|
||||
},
|
||||
onShareAppMessage() {
|
||||
return this.$t.mpShare
|
||||
},
|
||||
// #ifdef MP-WEIXIN
|
||||
onShareTimeline() {
|
||||
return {
|
||||
title: this.$t.mpShare.title,
|
||||
query: this.$t.mpShare.path.substring(this.$t.mpShare.path.indexOf('?') + 1, this.$t.mpShare.path.length),
|
||||
imageUrl: this.$t.mpShare.imageUrl
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
61
tuniao-ui/libs/mixin/touch.js
Normal file
61
tuniao-ui/libs/mixin/touch.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const MIN_DISTANCE = 10
|
||||
|
||||
function getDirection(x, y) {
|
||||
if (x > y && x > MIN_DISTANCE) {
|
||||
return 'horizontal'
|
||||
}
|
||||
if (y > x && y > MIN_DISTANCE) {
|
||||
return 'vertical'
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
touchStart(e) {
|
||||
this.resetTouchStatus()
|
||||
const touch = this.getTouchPoint(e)
|
||||
this.startX = touch.x
|
||||
this.startY = touch.y
|
||||
},
|
||||
touchMove(e) {
|
||||
const touch = this.getTouchPoint(e)
|
||||
this.deltaX = touch.x - this.startX
|
||||
this.deltaY = touch.y - this.startY
|
||||
this.offsetX = Math.abs(this.deltaX)
|
||||
this.offsetY = Math.abs(this.deltaY)
|
||||
this.direction = this.direction || getDirection(this.offsetX, this.offsetY)
|
||||
},
|
||||
getTouchPoint(e) {
|
||||
if (!e) {
|
||||
return {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
}
|
||||
if (e.touches && e.touches[0]) {
|
||||
return {
|
||||
x: e.touches[0].pageX,
|
||||
y: e.touches[0].pageY
|
||||
}
|
||||
}
|
||||
if (e.changedTouches && e.changedTouches[0]) {
|
||||
return {
|
||||
x: e.changedTouches[0].pageX,
|
||||
y: e.changedTouches[0].pageY
|
||||
}
|
||||
}
|
||||
return {
|
||||
x: e.clientX || 0,
|
||||
y: e.clientY || 0
|
||||
}
|
||||
},
|
||||
resetTouchStatus() {
|
||||
this.direction = ''
|
||||
this.deltaX = 0
|
||||
this.deltaY = 0
|
||||
this.offsetX = 0
|
||||
this.offsetY = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
1
tuniao-ui/libs/utils/area.js
Normal file
1
tuniao-ui/libs/utils/area.js
Normal file
File diff suppressed because one or more lines are too long
1356
tuniao-ui/libs/utils/async-validator.js
Normal file
1356
tuniao-ui/libs/utils/async-validator.js
Normal file
File diff suppressed because it is too large
Load Diff
546
tuniao-ui/libs/utils/calendar.js
Normal file
546
tuniao-ui/libs/utils/calendar.js
Normal file
@@ -0,0 +1,546 @@
|
||||
/**
|
||||
* @1900-2100区间内的公历、农历互转
|
||||
* @charset UTF-8
|
||||
* @github https://github.com/jjonline/calendar.js
|
||||
* @Author Jea杨(JJonline@JJonline.Cn)
|
||||
* @Time 2014-7-21
|
||||
* @Time 2016-8-13 Fixed 2033hex、Attribution Annals
|
||||
* @Time 2016-9-25 Fixed lunar LeapMonth Param Bug
|
||||
* @Time 2017-7-24 Fixed use getTerm Func Param Error.use solar year,NOT lunar year
|
||||
* @Version 1.0.3
|
||||
* @公历转农历:calendar.solar2lunar(1987,11,01); //[you can ignore params of prefix 0]
|
||||
* @农历转公历:calendar.lunar2solar(1987,09,10); //[you can ignore params of prefix 0]
|
||||
*/
|
||||
/* eslint-disable */
|
||||
var calendar = {
|
||||
|
||||
/**
|
||||
* 农历1900-2100的润大小信息表
|
||||
* @Array Of Property
|
||||
* @return Hex
|
||||
*/
|
||||
lunarInfo: [0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, // 1900-1909
|
||||
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, // 1910-1919
|
||||
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, // 1920-1929
|
||||
0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, // 1930-1939
|
||||
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, // 1940-1949
|
||||
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, // 1950-1959
|
||||
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, // 1960-1969
|
||||
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, // 1970-1979
|
||||
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, // 1980-1989
|
||||
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, // 1990-1999
|
||||
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, // 2000-2009
|
||||
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, // 2010-2019
|
||||
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, // 2020-2029
|
||||
0x05aa0, 0x076a3, 0x096d0, 0x04afb, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, // 2030-2039
|
||||
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, // 2040-2049
|
||||
/** Add By JJonline@JJonline.Cn**/
|
||||
0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, // 2050-2059
|
||||
0x0a2e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, // 2060-2069
|
||||
0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, // 2070-2079
|
||||
0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, // 2080-2089
|
||||
0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, // 2090-2099
|
||||
0x0d520], // 2100
|
||||
|
||||
/**
|
||||
* 公历每个月份的天数普通表
|
||||
* @Array Of Property
|
||||
* @return Number
|
||||
*/
|
||||
solarMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
||||
|
||||
/**
|
||||
* 天干地支之天干速查表
|
||||
* @Array Of Property trans["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
|
||||
* @return Cn string
|
||||
*/
|
||||
Gan: ['\u7532', '\u4e59', '\u4e19', '\u4e01', '\u620a', '\u5df1', '\u5e9a', '\u8f9b', '\u58ec', '\u7678'],
|
||||
|
||||
/**
|
||||
* 天干地支之地支速查表
|
||||
* @Array Of Property
|
||||
* @trans["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
|
||||
* @return Cn string
|
||||
*/
|
||||
Zhi: ['\u5b50', '\u4e11', '\u5bc5', '\u536f', '\u8fb0', '\u5df3', '\u5348', '\u672a', '\u7533', '\u9149', '\u620c', '\u4ea5'],
|
||||
|
||||
/**
|
||||
* 天干地支之地支速查表<=>生肖
|
||||
* @Array Of Property
|
||||
* @trans["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
|
||||
* @return Cn string
|
||||
*/
|
||||
Animals: ['\u9f20', '\u725b', '\u864e', '\u5154', '\u9f99', '\u86c7', '\u9a6c', '\u7f8a', '\u7334', '\u9e21', '\u72d7', '\u732a'],
|
||||
|
||||
/**
|
||||
* 24节气速查表
|
||||
* @Array Of Property
|
||||
* @trans["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"]
|
||||
* @return Cn string
|
||||
*/
|
||||
solarTerm: ['\u5c0f\u5bd2', '\u5927\u5bd2', '\u7acb\u6625', '\u96e8\u6c34', '\u60ca\u86f0', '\u6625\u5206', '\u6e05\u660e', '\u8c37\u96e8', '\u7acb\u590f', '\u5c0f\u6ee1', '\u8292\u79cd', '\u590f\u81f3', '\u5c0f\u6691', '\u5927\u6691', '\u7acb\u79cb', '\u5904\u6691', '\u767d\u9732', '\u79cb\u5206', '\u5bd2\u9732', '\u971c\u964d', '\u7acb\u51ac', '\u5c0f\u96ea', '\u5927\u96ea', '\u51ac\u81f3'],
|
||||
|
||||
/**
|
||||
* 1900-2100各年的24节气日期速查表
|
||||
* @Array Of Property
|
||||
* @return 0x string For splice
|
||||
*/
|
||||
sTermInfo: ['9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bcf97c3598082c95f8c965cc920f',
|
||||
'97bd0b06bdb0722c965ce1cfcc920f', 'b027097bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||
'97bcf97c359801ec95f8c965cc920f', '97bd0b06bdb0722c965ce1cfcc920f', 'b027097bd097c36b0b6fc9274c91aa',
|
||||
'97b6b97bd19801ec9210c965cc920e', '97bcf97c359801ec95f8c965cc920f', '97bd0b06bdb0722c965ce1cfcc920f',
|
||||
'b027097bd097c36b0b6fc9274c91aa', '9778397bd19801ec9210c965cc920e', '97b6b97bd19801ec95f8c965cc920f',
|
||||
'97bd09801d98082c95f8e1cfcc920f', '97bd097bd097c36b0b6fc9210c8dc2', '9778397bd197c36c9210c9274c91aa',
|
||||
'97b6b97bd19801ec95f8c965cc920e', '97bd09801d98082c95f8e1cfcc920f', '97bd097bd097c36b0b6fc9210c8dc2',
|
||||
'9778397bd097c36c9210c9274c91aa', '97b6b97bd19801ec95f8c965cc920e', '97bcf97c3598082c95f8e1cfcc920f',
|
||||
'97bd097bd097c36b0b6fc9210c8dc2', '9778397bd097c36c9210c9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||
'97bcf97c3598082c95f8c965cc920f', '97bd097bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||
'97b6b97bd19801ec9210c965cc920e', '97bcf97c3598082c95f8c965cc920f', '97bd097bd097c35b0b6fc920fb0722',
|
||||
'9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bcf97c359801ec95f8c965cc920f',
|
||||
'97bd097bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||
'97bcf97c359801ec95f8c965cc920f', '97bd097bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||
'97b6b97bd19801ec9210c965cc920e', '97bcf97c359801ec95f8c965cc920f', '97bd097bd07f595b0b6fc920fb0722',
|
||||
'9778397bd097c36b0b6fc9210c8dc2', '9778397bd19801ec9210c9274c920e', '97b6b97bd19801ec95f8c965cc920f',
|
||||
'97bd07f5307f595b0b0bc920fb0722', '7f0e397bd097c36b0b6fc9210c8dc2', '9778397bd097c36c9210c9274c920e',
|
||||
'97b6b97bd19801ec95f8c965cc920f', '97bd07f5307f595b0b0bc920fb0722', '7f0e397bd097c36b0b6fc9210c8dc2',
|
||||
'9778397bd097c36c9210c9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bd07f1487f595b0b0bc920fb0722',
|
||||
'7f0e397bd097c36b0b6fc9210c8dc2', '9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||
'97bcf7f1487f595b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||
'97b6b97bd19801ec9210c965cc920e', '97bcf7f1487f595b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722',
|
||||
'9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bcf7f1487f531b0b0bb0b6fb0722',
|
||||
'7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||
'97bcf7f1487f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||
'97b6b97bd19801ec9210c9274c920e', '97bcf7f0e47f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722',
|
||||
'9778397bd097c36b0b6fc9210c91aa', '97b6b97bd197c36c9210c9274c920e', '97bcf7f0e47f531b0b0bb0b6fb0722',
|
||||
'7f0e397bd07f595b0b0bc920fb0722', '9778397bd097c36b0b6fc9210c8dc2', '9778397bd097c36c9210c9274c920e',
|
||||
'97b6b7f0e47f531b0723b0b6fb0722', '7f0e37f5307f595b0b0bc920fb0722', '7f0e397bd097c36b0b6fc9210c8dc2',
|
||||
'9778397bd097c36b0b70c9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721', '7f0e37f1487f595b0b0bb0b6fb0722',
|
||||
'7f0e397bd097c35b0b6fc9210c8dc2', '9778397bd097c36b0b6fc9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721',
|
||||
'7f0e27f1487f595b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||
'97b6b7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722',
|
||||
'9778397bd097c36b0b6fc9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722',
|
||||
'7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721',
|
||||
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||
'97b6b7f0e47f531b0723b0787b0721', '7f0e27f0e47f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722',
|
||||
'9778397bd097c36b0b6fc9210c91aa', '97b6b7f0e47f149b0723b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722',
|
||||
'7f0e397bd07f595b0b0bc920fb0722', '9778397bd097c36b0b6fc9210c8dc2', '977837f0e37f149b0723b0787b0721',
|
||||
'7f07e7f0e47f531b0723b0b6fb0722', '7f0e37f5307f595b0b0bc920fb0722', '7f0e397bd097c35b0b6fc9210c8dc2',
|
||||
'977837f0e37f14998082b0787b0721', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e37f1487f595b0b0bb0b6fb0722',
|
||||
'7f0e397bd097c35b0b6fc9210c8dc2', '977837f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722', '977837f0e37f14998082b0787b06bd',
|
||||
'7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722',
|
||||
'977837f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722',
|
||||
'7f0e397bd07f595b0b0bc920fb0722', '977837f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722', '977837f0e37f14998082b0787b06bd',
|
||||
'7f07e7f0e47f149b0723b0787b0721', '7f0e27f0e47f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722',
|
||||
'977837f0e37f14998082b0723b06bd', '7f07e7f0e37f149b0723b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722',
|
||||
'7f0e397bd07f595b0b0bc920fb0722', '977837f0e37f14898082b0723b02d5', '7ec967f0e37f14998082b0787b0721',
|
||||
'7f07e7f0e47f531b0723b0b6fb0722', '7f0e37f1487f595b0b0bb0b6fb0722', '7f0e37f0e37f14898082b0723b02d5',
|
||||
'7ec967f0e37f14998082b0787b0721', '7f07e7f0e47f531b0723b0b6fb0722', '7f0e37f1487f531b0b0bb0b6fb0722',
|
||||
'7f0e37f0e37f14898082b0723b02d5', '7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||
'7f0e37f1487f531b0b0bb0b6fb0722', '7f0e37f0e37f14898082b072297c35', '7ec967f0e37f14998082b0787b06bd',
|
||||
'7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722', '7f0e37f0e37f14898082b072297c35',
|
||||
'7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722',
|
||||
'7f0e37f0e366aa89801eb072297c35', '7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f149b0723b0787b0721',
|
||||
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e37f0e366aa89801eb072297c35', '7ec967f0e37f14998082b0723b06bd',
|
||||
'7f07e7f0e47f149b0723b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722', '7f0e37f0e366aa89801eb072297c35',
|
||||
'7ec967f0e37f14998082b0723b06bd', '7f07e7f0e37f14998083b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722',
|
||||
'7f0e37f0e366aa89801eb072297c35', '7ec967f0e37f14898082b0723b02d5', '7f07e7f0e37f14998082b0787b0721',
|
||||
'7f07e7f0e47f531b0723b0b6fb0722', '7f0e36665b66aa89801e9808297c35', '665f67f0e37f14898082b0723b02d5',
|
||||
'7ec967f0e37f14998082b0787b0721', '7f07e7f0e47f531b0723b0b6fb0722', '7f0e36665b66a449801e9808297c35',
|
||||
'665f67f0e37f14898082b0723b02d5', '7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||
'7f0e36665b66a449801e9808297c35', '665f67f0e37f14898082b072297c35', '7ec967f0e37f14998082b0787b06bd',
|
||||
'7f07e7f0e47f531b0723b0b6fb0721', '7f0e26665b66a449801e9808297c35', '665f67f0e37f1489801eb072297c35',
|
||||
'7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722'],
|
||||
|
||||
/**
|
||||
* 数字转中文速查表
|
||||
* @Array Of Property
|
||||
* @trans ['日','一','二','三','四','五','六','七','八','九','十']
|
||||
* @return Cn string
|
||||
*/
|
||||
nStr1: ['\u65e5', '\u4e00', '\u4e8c', '\u4e09', '\u56db', '\u4e94', '\u516d', '\u4e03', '\u516b', '\u4e5d', '\u5341'],
|
||||
|
||||
/**
|
||||
* 日期转农历称呼速查表
|
||||
* @Array Of Property
|
||||
* @trans ['初','十','廿','卅']
|
||||
* @return Cn string
|
||||
*/
|
||||
nStr2: ['\u521d', '\u5341', '\u5eff', '\u5345'],
|
||||
|
||||
/**
|
||||
* 月份转农历称呼速查表
|
||||
* @Array Of Property
|
||||
* @trans ['正','一','二','三','四','五','六','七','八','九','十','冬','腊']
|
||||
* @return Cn string
|
||||
*/
|
||||
nStr3: ['\u6b63', '\u4e8c', '\u4e09', '\u56db', '\u4e94', '\u516d', '\u4e03', '\u516b', '\u4e5d', '\u5341', '\u51ac', '\u814a'],
|
||||
|
||||
/**
|
||||
* 返回农历y年一整年的总天数
|
||||
* @param lunar Year
|
||||
* @return Number
|
||||
* @eg:var count = calendar.lYearDays(1987) ;//count=387
|
||||
*/
|
||||
lYearDays: function (y) {
|
||||
var i; var sum = 348
|
||||
for (i = 0x8000; i > 0x8; i >>= 1) { sum += (this.lunarInfo[y - 1900] & i) ? 1 : 0 }
|
||||
return (sum + this.leapDays(y))
|
||||
},
|
||||
|
||||
/**
|
||||
* 返回农历y年闰月是哪个月;若y年没有闰月 则返回0
|
||||
* @param lunar Year
|
||||
* @return Number (0-12)
|
||||
* @eg:var leapMonth = calendar.leapMonth(1987) ;//leapMonth=6
|
||||
*/
|
||||
leapMonth: function (y) { // 闰字编码 \u95f0
|
||||
return (this.lunarInfo[y - 1900] & 0xf)
|
||||
},
|
||||
|
||||
/**
|
||||
* 返回农历y年闰月的天数 若该年没有闰月则返回0
|
||||
* @param lunar Year
|
||||
* @return Number (0、29、30)
|
||||
* @eg:var leapMonthDay = calendar.leapDays(1987) ;//leapMonthDay=29
|
||||
*/
|
||||
leapDays: function (y) {
|
||||
if (this.leapMonth(y)) {
|
||||
return ((this.lunarInfo[y - 1900] & 0x10000) ? 30 : 29)
|
||||
}
|
||||
return (0)
|
||||
},
|
||||
|
||||
/**
|
||||
* 返回农历y年m月(非闰月)的总天数,计算m为闰月时的天数请使用leapDays方法
|
||||
* @param lunar Year
|
||||
* @return Number (-1、29、30)
|
||||
* @eg:var MonthDay = calendar.monthDays(1987,9) ;//MonthDay=29
|
||||
*/
|
||||
monthDays: function (y, m) {
|
||||
if (m > 12 || m < 1) { return -1 }// 月份参数从1至12,参数错误返回-1
|
||||
return ((this.lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29)
|
||||
},
|
||||
|
||||
/**
|
||||
* 返回公历(!)y年m月的天数
|
||||
* @param solar Year
|
||||
* @return Number (-1、28、29、30、31)
|
||||
* @eg:var solarMonthDay = calendar.leapDays(1987) ;//solarMonthDay=30
|
||||
*/
|
||||
solarDays: function (y, m) {
|
||||
if (m > 12 || m < 1) { return -1 } // 若参数错误 返回-1
|
||||
var ms = m - 1
|
||||
if (ms == 1) { // 2月份的闰平规律测算后确认返回28或29
|
||||
return (((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0)) ? 29 : 28)
|
||||
} else {
|
||||
return (this.solarMonth[ms])
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 农历年份转换为干支纪年
|
||||
* @param lYear 农历年的年份数
|
||||
* @return Cn string
|
||||
*/
|
||||
toGanZhiYear: function (lYear) {
|
||||
var ganKey = (lYear - 3) % 10
|
||||
var zhiKey = (lYear - 3) % 12
|
||||
if (ganKey == 0) ganKey = 10// 如果余数为0则为最后一个天干
|
||||
if (zhiKey == 0) zhiKey = 12// 如果余数为0则为最后一个地支
|
||||
return this.Gan[ganKey - 1] + this.Zhi[zhiKey - 1]
|
||||
},
|
||||
|
||||
/**
|
||||
* 公历月、日判断所属星座
|
||||
* @param cMonth [description]
|
||||
* @param cDay [description]
|
||||
* @return Cn string
|
||||
*/
|
||||
toAstro: function (cMonth, cDay) {
|
||||
var s = '\u9b54\u7faf\u6c34\u74f6\u53cc\u9c7c\u767d\u7f8a\u91d1\u725b\u53cc\u5b50\u5de8\u87f9\u72ee\u5b50\u5904\u5973\u5929\u79e4\u5929\u874e\u5c04\u624b\u9b54\u7faf'
|
||||
var arr = [20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22]
|
||||
return s.substr(cMonth * 2 - (cDay < arr[cMonth - 1] ? 2 : 0), 2) + '\u5ea7'// 座
|
||||
},
|
||||
|
||||
/**
|
||||
* 传入offset偏移量返回干支
|
||||
* @param offset 相对甲子的偏移量
|
||||
* @return Cn string
|
||||
*/
|
||||
toGanZhi: function (offset) {
|
||||
return this.Gan[offset % 10] + this.Zhi[offset % 12]
|
||||
},
|
||||
|
||||
/**
|
||||
* 传入公历(!)y年获得该年第n个节气的公历日期
|
||||
* @param y公历年(1900-2100);n二十四节气中的第几个节气(1~24);从n=1(小寒)算起
|
||||
* @return day Number
|
||||
* @eg:var _24 = calendar.getTerm(1987,3) ;//_24=4;意即1987年2月4日立春
|
||||
*/
|
||||
getTerm: function (y, n) {
|
||||
if (y < 1900 || y > 2100) { return -1 }
|
||||
if (n < 1 || n > 24) { return -1 }
|
||||
var _table = this.sTermInfo[y - 1900]
|
||||
var _info = [
|
||||
parseInt('0x' + _table.substr(0, 5)).toString(),
|
||||
parseInt('0x' + _table.substr(5, 5)).toString(),
|
||||
parseInt('0x' + _table.substr(10, 5)).toString(),
|
||||
parseInt('0x' + _table.substr(15, 5)).toString(),
|
||||
parseInt('0x' + _table.substr(20, 5)).toString(),
|
||||
parseInt('0x' + _table.substr(25, 5)).toString()
|
||||
]
|
||||
var _calday = [
|
||||
_info[0].substr(0, 1),
|
||||
_info[0].substr(1, 2),
|
||||
_info[0].substr(3, 1),
|
||||
_info[0].substr(4, 2),
|
||||
|
||||
_info[1].substr(0, 1),
|
||||
_info[1].substr(1, 2),
|
||||
_info[1].substr(3, 1),
|
||||
_info[1].substr(4, 2),
|
||||
|
||||
_info[2].substr(0, 1),
|
||||
_info[2].substr(1, 2),
|
||||
_info[2].substr(3, 1),
|
||||
_info[2].substr(4, 2),
|
||||
|
||||
_info[3].substr(0, 1),
|
||||
_info[3].substr(1, 2),
|
||||
_info[3].substr(3, 1),
|
||||
_info[3].substr(4, 2),
|
||||
|
||||
_info[4].substr(0, 1),
|
||||
_info[4].substr(1, 2),
|
||||
_info[4].substr(3, 1),
|
||||
_info[4].substr(4, 2),
|
||||
|
||||
_info[5].substr(0, 1),
|
||||
_info[5].substr(1, 2),
|
||||
_info[5].substr(3, 1),
|
||||
_info[5].substr(4, 2)
|
||||
]
|
||||
return parseInt(_calday[n - 1])
|
||||
},
|
||||
|
||||
/**
|
||||
* 传入农历数字月份返回汉语通俗表示法
|
||||
* @param lunar month
|
||||
* @return Cn string
|
||||
* @eg:var cnMonth = calendar.toChinaMonth(12) ;//cnMonth='腊月'
|
||||
*/
|
||||
toChinaMonth: function (m) { // 月 => \u6708
|
||||
if (m > 12 || m < 1) { return -1 } // 若参数错误 返回-1
|
||||
var s = this.nStr3[m - 1]
|
||||
s += '\u6708'// 加上月字
|
||||
return s
|
||||
},
|
||||
|
||||
/**
|
||||
* 传入农历日期数字返回汉字表示法
|
||||
* @param lunar day
|
||||
* @return Cn string
|
||||
* @eg:var cnDay = calendar.toChinaDay(21) ;//cnMonth='廿一'
|
||||
*/
|
||||
toChinaDay: function (d) { // 日 => \u65e5
|
||||
var s
|
||||
switch (d) {
|
||||
case 10:
|
||||
s = '\u521d\u5341'; break
|
||||
case 20:
|
||||
s = '\u4e8c\u5341'; break
|
||||
break
|
||||
case 30:
|
||||
s = '\u4e09\u5341'; break
|
||||
break
|
||||
default:
|
||||
s = this.nStr2[Math.floor(d / 10)]
|
||||
s += this.nStr1[d % 10]
|
||||
}
|
||||
return (s)
|
||||
},
|
||||
|
||||
/**
|
||||
* 年份转生肖[!仅能大致转换] => 精确划分生肖分界线是“立春”
|
||||
* @param y year
|
||||
* @return Cn string
|
||||
* @eg:var animal = calendar.getAnimal(1987) ;//animal='兔'
|
||||
*/
|
||||
getAnimal: function (y) {
|
||||
return this.Animals[(y - 4) % 12]
|
||||
},
|
||||
|
||||
/**
|
||||
* 传入阳历年月日获得详细的公历、农历object信息 <=>JSON
|
||||
* @param y solar year
|
||||
* @param m solar month
|
||||
* @param d solar day
|
||||
* @return JSON object
|
||||
* @eg:console.log(calendar.solar2lunar(1987,11,01));
|
||||
*/
|
||||
solar2lunar: function (y, m, d) { // 参数区间1900.1.31~2100.12.31
|
||||
// 年份限定、上限
|
||||
if (y < 1900 || y > 2100) {
|
||||
return -1// undefined转换为数字变为NaN
|
||||
}
|
||||
// 公历传参最下限
|
||||
if (y == 1900 && m == 1 && d < 31) {
|
||||
return -1
|
||||
}
|
||||
// 未传参 获得当天
|
||||
if (!y) {
|
||||
var objDate = new Date()
|
||||
} else {
|
||||
var objDate = new Date(y, parseInt(m) - 1, d)
|
||||
}
|
||||
var i; var leap = 0; var temp = 0
|
||||
// 修正ymd参数
|
||||
var y = objDate.getFullYear()
|
||||
var m = objDate.getMonth() + 1
|
||||
var d = objDate.getDate()
|
||||
var offset = (Date.UTC(objDate.getFullYear(), objDate.getMonth(), objDate.getDate()) - Date.UTC(1900, 0, 31)) / 86400000
|
||||
for (i = 1900; i < 2101 && offset > 0; i++) {
|
||||
temp = this.lYearDays(i)
|
||||
offset -= temp
|
||||
}
|
||||
if (offset < 0) {
|
||||
offset += temp; i--
|
||||
}
|
||||
|
||||
// 是否今天
|
||||
var isTodayObj = new Date()
|
||||
var isToday = false
|
||||
if (isTodayObj.getFullYear() == y && isTodayObj.getMonth() + 1 == m && isTodayObj.getDate() == d) {
|
||||
isToday = true
|
||||
}
|
||||
// 星期几
|
||||
var nWeek = objDate.getDay()
|
||||
var cWeek = this.nStr1[nWeek]
|
||||
// 数字表示周几顺应天朝周一开始的惯例
|
||||
if (nWeek == 0) {
|
||||
nWeek = 7
|
||||
}
|
||||
// 农历年
|
||||
var year = i
|
||||
var leap = this.leapMonth(i) // 闰哪个月
|
||||
var isLeap = false
|
||||
|
||||
// 效验闰月
|
||||
for (i = 1; i < 13 && offset > 0; i++) {
|
||||
// 闰月
|
||||
if (leap > 0 && i == (leap + 1) && isLeap == false) {
|
||||
--i
|
||||
isLeap = true; temp = this.leapDays(year) // 计算农历闰月天数
|
||||
} else {
|
||||
temp = this.monthDays(year, i)// 计算农历普通月天数
|
||||
}
|
||||
// 解除闰月
|
||||
if (isLeap == true && i == (leap + 1)) { isLeap = false }
|
||||
offset -= temp
|
||||
}
|
||||
// 闰月导致数组下标重叠取反
|
||||
if (offset == 0 && leap > 0 && i == leap + 1) {
|
||||
if (isLeap) {
|
||||
isLeap = false
|
||||
} else {
|
||||
isLeap = true; --i
|
||||
}
|
||||
}
|
||||
if (offset < 0) {
|
||||
offset += temp; --i
|
||||
}
|
||||
// 农历月
|
||||
var month = i
|
||||
// 农历日
|
||||
var day = offset + 1
|
||||
// 天干地支处理
|
||||
var sm = m - 1
|
||||
var gzY = this.toGanZhiYear(year)
|
||||
|
||||
// 当月的两个节气
|
||||
// bugfix-2017-7-24 11:03:38 use lunar Year Param `y` Not `year`
|
||||
var firstNode = this.getTerm(y, (m * 2 - 1))// 返回当月「节」为几日开始
|
||||
var secondNode = this.getTerm(y, (m * 2))// 返回当月「节」为几日开始
|
||||
|
||||
// 依据12节气修正干支月
|
||||
var gzM = this.toGanZhi((y - 1900) * 12 + m + 11)
|
||||
if (d >= firstNode) {
|
||||
gzM = this.toGanZhi((y - 1900) * 12 + m + 12)
|
||||
}
|
||||
|
||||
// 传入的日期的节气与否
|
||||
var isTerm = false
|
||||
var Term = null
|
||||
if (firstNode == d) {
|
||||
isTerm = true
|
||||
Term = this.solarTerm[m * 2 - 2]
|
||||
}
|
||||
if (secondNode == d) {
|
||||
isTerm = true
|
||||
Term = this.solarTerm[m * 2 - 1]
|
||||
}
|
||||
// 日柱 当月一日与 1900/1/1 相差天数
|
||||
var dayCyclical = Date.UTC(y, sm, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10
|
||||
var gzD = this.toGanZhi(dayCyclical + d - 1)
|
||||
// 该日期所属的星座
|
||||
var astro = this.toAstro(m, d)
|
||||
|
||||
return { 'lYear': year, 'lMonth': month, 'lDay': day, 'Animal': this.getAnimal(year), 'IMonthCn': (isLeap ? '\u95f0' : '') + this.toChinaMonth(month), 'IDayCn': this.toChinaDay(day), 'cYear': y, 'cMonth': m, 'cDay': d, 'gzYear': gzY, 'gzMonth': gzM, 'gzDay': gzD, 'isToday': isToday, 'isLeap': isLeap, 'nWeek': nWeek, 'ncWeek': '\u661f\u671f' + cWeek, 'isTerm': isTerm, 'Term': Term, 'astro': astro }
|
||||
},
|
||||
|
||||
/**
|
||||
* 传入农历年月日以及传入的月份是否闰月获得详细的公历、农历object信息 <=>JSON
|
||||
* @param y lunar year
|
||||
* @param m lunar month
|
||||
* @param d lunar day
|
||||
* @param isLeapMonth lunar month is leap or not.[如果是农历闰月第四个参数赋值true即可]
|
||||
* @return JSON object
|
||||
* @eg:console.log(calendar.lunar2solar(1987,9,10));
|
||||
*/
|
||||
lunar2solar: function (y, m, d, isLeapMonth) { // 参数区间1900.1.31~2100.12.1
|
||||
var isLeapMonth = !!isLeapMonth
|
||||
var leapOffset = 0
|
||||
var leapMonth = this.leapMonth(y)
|
||||
var leapDay = this.leapDays(y)
|
||||
if (isLeapMonth && (leapMonth != m)) { return -1 }// 传参要求计算该闰月公历 但该年得出的闰月与传参的月份并不同
|
||||
if (y == 2100 && m == 12 && d > 1 || y == 1900 && m == 1 && d < 31) { return -1 }// 超出了最大极限值
|
||||
var day = this.monthDays(y, m)
|
||||
var _day = day
|
||||
// bugFix 2016-9-25
|
||||
// if month is leap, _day use leapDays method
|
||||
if (isLeapMonth) {
|
||||
_day = this.leapDays(y, m)
|
||||
}
|
||||
if (y < 1900 || y > 2100 || d > _day) { return -1 }// 参数合法性效验
|
||||
|
||||
// 计算农历的时间差
|
||||
var offset = 0
|
||||
for (var i = 1900; i < y; i++) {
|
||||
offset += this.lYearDays(i)
|
||||
}
|
||||
var leap = 0; var isAdd = false
|
||||
for (var i = 1; i < m; i++) {
|
||||
leap = this.leapMonth(y)
|
||||
if (!isAdd) { // 处理闰月
|
||||
if (leap <= i && leap > 0) {
|
||||
offset += this.leapDays(y); isAdd = true
|
||||
}
|
||||
}
|
||||
offset += this.monthDays(y, i)
|
||||
}
|
||||
// 转换闰月农历 需补充该年闰月的前一个月的时差
|
||||
if (isLeapMonth) { offset += day }
|
||||
// 1900年农历正月一日的公历时间为1900年1月30日0时0分0秒(该时间也是本农历的最开始起始点)
|
||||
var stmap = Date.UTC(1900, 1, 30, 0, 0, 0)
|
||||
var calObj = new Date((offset + d - 31) * 86400000 + stmap)
|
||||
var cY = calObj.getUTCFullYear()
|
||||
var cM = calObj.getUTCMonth() + 1
|
||||
var cD = calObj.getUTCDate()
|
||||
|
||||
return this.solar2lunar(cY, cM, cD)
|
||||
}
|
||||
}
|
||||
|
||||
export default calendar
|
||||
1
tuniao-ui/libs/utils/city.js
Normal file
1
tuniao-ui/libs/utils/city.js
Normal file
File diff suppressed because one or more lines are too long
55
tuniao-ui/libs/utils/emitter.js
Normal file
55
tuniao-ui/libs/utils/emitter.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 递归使用call方式 this指向
|
||||
*
|
||||
* @param {String} componentName 需要查找的组件的名称
|
||||
* @param {String} eventName 事件名称
|
||||
* @param {Object} params 需要传递的参数
|
||||
*/
|
||||
function broadcast(componentName, eventName, params) {
|
||||
// 循环子节点找到需要的节点,没有查找到就递归进行查找
|
||||
this.$children.map(child => {
|
||||
if (componentName === child.$options.name) {
|
||||
child.$emit.apply(child, [eventName].concat(params))
|
||||
} else {
|
||||
broadcast.apply(child, [componentName, eventName].concat(params))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
/**
|
||||
* 派发 向上查找一个
|
||||
* @param {Object} componentName 需要查找的组件的名称
|
||||
* @param {Object} eventName 事件名称
|
||||
* @param {Object} params 需要传递的参数
|
||||
*/
|
||||
dispatch(componentName, eventName, params) {
|
||||
// 找到最近父节点 $root 根节点
|
||||
let parent = this.$parent || this.$root
|
||||
// 获取当前实例的名称
|
||||
let name = parent.$options.name
|
||||
|
||||
// 当前存在节点并且当前节点没有名称或者名称不等于我们要查找的节点名称,则继续遍历
|
||||
while (parent && (!name || name !== componentName)) {
|
||||
parent = parent.$parent
|
||||
if (parent) {
|
||||
name = parent.$options.name
|
||||
}
|
||||
}
|
||||
// 如果有节点则表示找到
|
||||
if (parent) {
|
||||
parent.$emit.apply(parent, [eventName].concat(params))
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 广播 向下查找多个
|
||||
* @param {Object} componentName 需要查找的组件的名称
|
||||
* @param {Object} eventName 事件名称
|
||||
* @param {Object} params 需要传递的参数
|
||||
*/
|
||||
broadcast(componentName, eventName, params) {
|
||||
broadcast.call(this, componentName, eventName, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
1
tuniao-ui/libs/utils/province.js
Normal file
1
tuniao-ui/libs/utils/province.js
Normal file
@@ -0,0 +1 @@
|
||||
var provinceData=[{"label":"北京市","value":"11"},{"label":"天津市","value":"12"},{"label":"河北省","value":"13"},{"label":"山西省","value":"14"},{"label":"内蒙古自治区","value":"15"},{"label":"辽宁省","value":"21"},{"label":"吉林省","value":"22"},{"label":"黑龙江省","value":"23"},{"label":"上海市","value":"31"},{"label":"江苏省","value":"32"},{"label":"浙江省","value":"33"},{"label":"安徽省","value":"34"},{"label":"福建省","value":"35"},{"label":"江西省","value":"36"},{"label":"山东省","value":"37"},{"label":"河南省","value":"41"},{"label":"湖北省","value":"42"},{"label":"湖南省","value":"43"},{"label":"广东省","value":"44"},{"label":"广西壮族自治区","value":"45"},{"label":"海南省","value":"46"},{"label":"重庆市","value":"50"},{"label":"四川省","value":"51"},{"label":"贵州省","value":"52"},{"label":"云南省","value":"53"},{"label":"西藏自治区","value":"54"},{"label":"陕西省","value":"61"},{"label":"甘肃省","value":"62"},{"label":"青海省","value":"63"},{"label":"宁夏回族自治区","value":"64"},{"label":"新疆维吾尔自治区","value":"65"},{"label":"台湾","value":"66"},{"label":"香港","value":"67"},{"label":"澳门","value":"68"}];export default provinceData;
|
||||
Reference in New Issue
Block a user