1.0.1 • Published 3 years ago

hotspot-vue3 v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

hotspot-vue3 · npm yarn github npm.io npm.io npm.io

A hot zone generation tool for VUE3 + TS projects 中文文档

image

Try out the demo!

Plug-in installation

yarn add hotspot-vue3

# or

npm install hotspot-vue3 --save

The plug-in USES

  • Introduced in the business component file
import Hotspot from "hotspot-vue3";
  • In your business code, use it as a normal component
<template>
  <div class="hotapp">
    <hotspot
      :image="image"
      :zonesInit="zones"
      :types="types"
      :minSize="52"
      :switchOptions="{
        isShowSign: true,
        isShowDelete: true,
        isOverlap: false,
        isShowActive: true
      }"
      :styleOptions="{}"
      @add="handleAdd"
    >
      <!-- <template #sign="{ zone, index }">
        {{ zone }}
        {{ index }}
      </template>
      <template #delete="{ index }">
        {{ index }}
      </template> -->
    </hotspot>
    <div class="hotapp__display">
      <button type="primary" @click="handleAdd">Add hot spots</button>
      <input
        type="text"
        v-for="(zone, index) in zones"
        :key="index"
        v-model="zone.url"
        :placeholder="`Area ${index + 1} url`"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";
import Hotspot from "hotspot-vue3";

type MoreUrl = {
  [key in string | number]: string;
};
interface ZoneType {
  topPer: number;
  leftPer: number;
  widthPer: number;
  heightPer: number;
  url?: string | MoreUrl;
  active?: boolean;
  key?: string;
}

@Options({
  components: {
    Hotspot
  }
})
export default class App extends Vue {
  // image url
  image =
    "https://github.com/shadow-Fiend/readme_image/blob/master/big_fish.jpeg";
  zones = [] as ZoneType[];
  types = "move";

  handleAdd(zon: ZoneType) {
    let zone: ZoneType;
    if (zon.topPer) {
      // If this parameter exists, drag to create a hot zone
      zone = zon;
      zone.url = "https://github.com";
      this.types = "move"; // When Max hot zones exist, verify by dragging or clicking to Max
    } else {
      // Create hot zones with buttons
      zone = {
        heightPer: 0.2027, //20.27%
        leftPer: 0.2027,
        topPer: 0.2027,
        widthPer: 0.1027,
        url: "https://github.com",
        key: String(Math.random())
      } as ZoneType;
      this.types = "btn"; // When Max hot zones exist, verify by dragging or clicking to Max
    }
    this.zones.push(zone); // Hotspot data
  }
}
</script>

<style lang="scss" scoped>
.hotapp {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 555px;
  min-width: 1000px;

  &__display {
    margin-top: 24px;

    > input {
      margin-left: 10px;
    }
  }
}
</style>

Parameters that

As shown in the sample code, import this component directly, and control all other functions through properties.

Here's what each property means:

Hotspot Attributes

AttributeDescriptionTypeAccepted ValuesDefault
imageUrl address of heat base mapString
zonesInitHot zone content, in array formArraytopPer、leftPer、widthPer、heightPer、url、active、key
maxThat is, the maximum number of displays in the current hot zone. If you do not set this parameter, it can be added indefinitelyNumber
typesThe way to add hot areasStringmove: Generated by dragging the mouse, btn: Generated by custom button click
switchOptionsHot zone switch propertiesObjectisShowSign、isShowDelete、isOverlap、isShowActive
styleOptionsHot zones display some color value propertiesObjectzoneBorderColor、zoneBgColor、zoneActiveBgColor

ZonesInit Atributes

AttributeDescriptionTypeAccepted ValuesDefault
topPerDistance from the top as a percentage of the total areaNumber
leftPerDistance to the left as a percentage of the total areaNumber
widthPerPercentage of hot zone width in total areaNumber
heightPerPercentage of hot zone height to total areaNumber
urlHot area link address, you can define your own object to save more parametersString / any
activeHot zone activation stateBoolean / undefinedfalse / undefined
keyHot zone key, used for unique identificationStringMath.random()

SwitchOptions Atributes

AttributeDescriptionTypeAccepted ValuesDefault
isShowSignWhether to display hot zone signsBooleantrue
isShowDeleteWhether to display the hot zone deletion signBooleantrue
isOverlapWhether coverage is allowed between hot zonesBooleanfalse
isShowActiveClick the hot zone to see if the active status is displayedBooleantrue

StyleOptions Atributes

AttributeDescriptionTypeAccepted ValuesDefault
zoneBorderColorHot zone border colorString#507bfb
zoneBgColorHot area background colorStringrgba(80, 123, 251, 0.1)
zoneActiveBgColorHot zone background color in active state. This color takes effect only when isShowActive is trueStringrgba(80, 123, 251, 0.4)

Write in the last

At this point, all the ways to use the plug-in are covered.

This plugin only supports vue3.x projects...

For more information about the source of the plugin, please visit the GitHub plugin repository:hotspot-vue3