Prechádzať zdrojové kódy

feat: 警情动态的选项通用组件封装

TwoKe945 1 rok pred
rodič
commit
38cab929ee

+ 4 - 14
app/src/views/HomeView.vue

@@ -6,7 +6,6 @@
         style="padding: 0px 35px; display: flex; justify-content: space-between"
       >
         <div>
-
           <border-panel
             height="302px"
             style="margin-bottom: 6px"
@@ -22,19 +21,6 @@
             2222
           </border-panel>
           <border-panel height="296px" title="自主管理"> 3333 </border-panel>
-        <border-panel height="302px" style="margin-bottom: 6px;" title="基础信息">
-          1111
-          <div class="firsts">
-            <FirstHight/>
-          </div>
-        </border-panel>
-        <border-panel height="346px" style="margin-bottom: 6px;"  title="隐患排查(一楼一策)">
-          2222
-        </border-panel>
-        <border-panel height="296px"  title="自主管理">
-          3333
-        </border-panel>
-
         </div>
         <div class="display: flex; ">
           <div class="map">
@@ -48,6 +34,10 @@
               :header-type="1"
             >
             <AlarmingSituationDynamics />
+            <template #ext-header>
+              <!-- TODO  实现警情动态点击事件 -->
+              <button-block />
+            </template>
             </border-panel>
           </div>
         </div>

+ 8 - 1
components/BorderPanel/index.vue

@@ -16,6 +16,7 @@
           textShadow: '0 1px 1px #0057FF',
         }"
       />
+      <div class="ext-header"><slot name="ext-header"></slot></div>
     </div>
     <div class="border-panel_content">
       <slot></slot>
@@ -67,7 +68,7 @@ export default {
 };
 </script>
 
-<style scoped>
+<style scoped lang="less">
 .border-panel {
   position: relative;
   height: var(--height);
@@ -87,6 +88,12 @@ export default {
   background-image: url("../assets/border-panel_header_1.svg");
   background-repeat: no-repeat;
   background-position: var(--header-ops) 0px;
+  display: flex;
+  justify-content: space-between;
+  .ext-header {
+    margin-right: 15px;
+    margin-top: 12px;
+  }
 }
 
 .border-panel::after {

+ 4 - 0
components/ButtonBlock/index.js

@@ -0,0 +1,4 @@
+import ButtonBlock from "./index.vue";
+import { withInstall } from "@zhgkpt/utils";
+
+export default withInstall(ButtonBlock);

+ 119 - 0
components/ButtonBlock/index.vue

@@ -0,0 +1,119 @@
+<script >
+import LinearText from '../LinearText';
+export default {
+  name: 'ButtonBlock',
+  components: {
+    LinearText
+  },
+  props: {
+    items: {
+      type: Array,
+      default: () => [
+        "本日",
+        "本周",
+        "本月"
+      ]
+    },
+    valueField: {
+      type: String,
+      default: ""
+    },
+    defaultIndex: {
+      type: Number,
+      default: 0
+    }
+  },
+  data() {
+    return {
+      currentItemIndex: 0,
+    }
+  },
+  emits: ["select-item"],
+  created() {
+    this.currentItemIndex = this.defaultIndex;
+  },
+  methods: {
+    /**
+     * 渲染当前节点的颜色
+     * @param {*} index 当前选项索引
+     * @param {*} color 选择时的颜色
+     */
+    renderCurrentItemColor(index, color) {
+      return this.currentItemIndex === index ? color : `${color}88`
+    },
+    /**
+     * 渲染文本内容
+     * @param {*} item 节点数据
+     */
+    renderText(item) {
+      if (this.valueField === '') {
+        return item
+      } else {
+        return item[this.valueField]
+      }
+    },
+    /**
+     * 点击节点处理器
+     * @param {*} index 当前点击的选项索引
+     */
+    onClickBlockItemHandler(index) {
+      this.currentItemIndex = index
+      this.$emit('select-item', index)
+    }
+  }
+}
+</script>
+
+<template >
+  <div class="button-block">
+    <div class="button-block_item" v-for="(item,index) in items" :key="index">
+      <linear-text :text="renderText(item)"
+      :startColor="renderCurrentItemColor(index, '#95CCFF')"
+      :endColor="renderCurrentItemColor(index, '#FFFFFF')"
+      fontSize="16px"   :ext-class="{
+        textShadow: `0 1px 1px ${renderCurrentItemColor(index, '#0057FF')}`
+      }" @click="onClickBlockItemHandler(index)" />
+    </div>
+  </div>
+</template>
+
+<style scoped lang='less'>
+.button-block {
+  display: flex;
+  border-radius: 5px;
+  box-sizing: border-box;
+  background: linear-gradient(
+    360deg,
+    #0094FF60 100%,
+    #0094FF00 0%
+  );
+  .button-block_item {
+    padding: 0px 8.5px 0px 8.5px;
+    cursor: pointer;
+  }
+  &::after {
+    content: "";
+    position: absolute;
+    top: 0px;
+    left: 0px;
+    padding: 1px;
+    box-sizing: border-box;
+    background: linear-gradient(360deg, #0c5a87 0%, rgba(0, 163, 255, 0) 100%);
+    /* 随便定义颜色 */
+    --mask-bg: linear-gradient(red, red);
+    --m-o: content-box, padding-box;
+    /* mask允许使用者通过遮罩或者裁切特定区域的图片的方式来隐藏一个元素的部分或者全部可见区域 */
+    /* 设置了用作元素蒙版层的图像,默认值为none,值为透明图片,或透明渐变 */
+    -webkit-mask-image: var(--mask-bg), var(--mask-bg);
+    /* 默认值为border-box,可选值与background-origin相同 */
+    -webkit-mask-origin: var(--m-o);
+    /* 默认值为border-box,可选值与background-clip相同 */
+    -webkit-mask-clip: var(--m-o);
+    /* exclude排除,只显示不重合的地方,Firefox支持4个属性 */
+    mask-composite: exclude;
+    /*只显示下方遮罩,重合的地方不显示*/
+    -webkit-mask-composite: destination-out;
+    pointer-events: none;
+  }
+}
+</style>

+ 1 - 1
components/LinearText/index.vue

@@ -1,5 +1,5 @@
 <template>
-  <div class="linear-text" :style="linearTextStyle" :data-text="text">
+  <div @click="e => $emit('click', e)" class="linear-text" :style="linearTextStyle" :data-text="text">
     {{ text }}
   </div>
 </template>

+ 3 - 2
components/index.js

@@ -1,6 +1,7 @@
 import BorderPanel from "./BorderPanel";
+import ButtonBlock from "./ButtonBlock";
 import LinearText from "./LinearText";
-const components = [BorderPanel, LinearText];
+const components = [BorderPanel, LinearText, ButtonBlock];
 
 function install(app) {
   components.forEach((item) => {
@@ -8,7 +9,7 @@ function install(app) {
   });
 }
 
-export { BorderPanel, LinearText };
+export { BorderPanel, LinearText, ButtonBlock };
 
 export default {
   install,