helang-pickerColor.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view v-show="isShow">
  3. <view class="shade" @tap="hide"></view>
  4. <view class="pop">
  5. <view class="flex_col" style="margin-bottom: 20upx;">
  6. <view class="preview" :style="{'backgroundColor':pickerColor}"></view>
  7. <view class="value">
  8. <text style="color: black;" v-if="pickerColor">颜色值:{{pickerColor}}</text>
  9. </view>
  10. <view class="ok" @tap="setColor">确定</view>
  11. </view>
  12. <view class="list flex_col" v-for="(item,index) in colorArr" :key="index">
  13. <view v-for="(v,i) in item" :key="i"
  14. :style="{'backgroundColor':v}"
  15. :data-color="v"
  16. :data-index="index"
  17. :data-i="i"
  18. :class="{'active':(index==pickerArr[0] && i==pickerArr[1])}"
  19. @tap="picker"></view>
  20. </view>
  21. <view :style="{'height':(bottom+'px')}"></view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. name:'picker-color',
  28. props:{
  29. isShow: {
  30. type: Boolean,
  31. default: false,
  32. },
  33. bottom:{
  34. type: Number,
  35. default: 0,
  36. }
  37. },
  38. data() {
  39. return {
  40. colorArr:[
  41. ['#000000','#111111','#222222','#333333','#444444','#666666','#999999','#CCCCCC','#EEEEEE','#FFFFFF'],
  42. ['#ff0000','#ff0033','#ff3399','#ff33cc','#cc00ff','#9900ff','#cc00cc','#cc0099','#cc3399','#cc0066'],
  43. ['#cc3300','#cc6600','#ff9933','#ff9966','#ff9999','#ff99cc','#ff99ff','#cc66ff','#9966ff','#cc33ff'],
  44. ['#663300','#996600','#996633','#cc9900','#a58800','#cccc00','#ffff66','#ffff99','#ffffcc','#ffcccc'],
  45. ['#336600','#669900','#009900','#009933','#00cc00','#66ff66','#339933','#339966','#009999','#33cccc'],
  46. ['#003366','#336699','#3366cc','#0099ff','#000099','#0000cc','#660066','#993366','#993333','#800000']
  47. ],
  48. pickerColor:'',
  49. pickerArr:[-1,-1]
  50. };
  51. },
  52. methods: {
  53. picker(e) {
  54. let data=e.currentTarget.dataset;
  55. this.pickerColor=data.color;
  56. this.pickerArr=[data.index,data.i];
  57. },
  58. hide(){
  59. this.$emit("callback",'');
  60. },
  61. setColor(){
  62. this.$emit("callback",this.pickerColor);
  63. }
  64. },
  65. }
  66. </script>
  67. <style scoped>
  68. .shade{
  69. position: fixed;
  70. top: 0;
  71. right: 0;
  72. bottom: 0;
  73. left: 0;
  74. background-color: rgba(0,0,0,0.5);
  75. z-index: 99;
  76. }
  77. .pop{
  78. position: fixed;
  79. right: 0;
  80. bottom: 0;
  81. left: 0;
  82. background-color: #fff;
  83. z-index: 100;
  84. padding: 20upx 20upx 10upx 20upx;
  85. font-size: 32upx;
  86. }
  87. .flex_col{
  88. display: flex;
  89. flex-direction: row;
  90. flex-wrap: nowrap;
  91. justify-content: flex-start;
  92. align-items: center;
  93. align-content: center;
  94. }
  95. .list{
  96. justify-content: space-between;
  97. }
  98. .list>view{
  99. width: 60upx;
  100. height: 60upx;
  101. margin-bottom: 10upx;
  102. box-sizing: border-box;
  103. border-radius: 3px;
  104. box-shadow: 0 0 2px #ccc;
  105. }
  106. .list .active{
  107. box-shadow: 0 0 2px #09f;
  108. transform:scale(1.05,1.05);
  109. }
  110. .preview{
  111. width: 180upx;
  112. height: 60upx;
  113. }
  114. .value{
  115. margin: 0 40upx;
  116. flex-grow: 1;
  117. }
  118. .ok{
  119. width: 160upx;
  120. height: 60upx;
  121. line-height: 60upx;
  122. text-align: center;
  123. background-color: #ff9933;
  124. color: #fff;
  125. border-radius: 4px;
  126. letter-spacing: 3px;
  127. font-size: 32upx;
  128. }
  129. .ok:active{
  130. background-color: rgb(255, 107, 34);
  131. }
  132. </style>