UNPKG

5.68 kBPlain TextView Raw
1<template>
2 <div
3 class="z-shape is-extension"
4 :class="[componentType, classes]"
5 :role="button === true ? 'button' : ''"
6 :style="responsive === true ? styles.main : zpos.main"
7 @mouseover="spotin"
8 @mouseout="spotout"
9 @mousedown="pulse"
10 @touchstart="pulse"
11 @mouseup="move">
12 <div v-if="!button" ref="spot" class="z-outer-spot" :style="styles.plate"></div>
13 <div class="z-pulse" ref="pulse"></div>
14 <z-knob v-if="knob" :qty.sync="computedQty" :unit="unit" :min="min" :max="max" />
15 <z-slider v-if="slider === true" :progress='progress' />
16 <div class="z-label" :class="labelPos" :style="$zircle.getThemeMode() === 'mode-light-filled' ? 'color: var(--accent-text-and-border-color);' : ''" v-if="label">
17 <div class="inside">
18 {{label}} <span v-if="pos === 'outside'"> {{progressLabel}}</span>
19 </div>
20 </div>
21 <div class="z-content">
22 <img v-if="imagePath" :src="imagePath" width="100%" height="100%" />
23 <slot v-if="!imagePath" name="image"></slot>
24 </div>
25 <div class="z-content" style="z-index: 10">
26 <span class="overflow">
27 <span v-if="pos === 'inside' || pos === undefined ">{{progressLabel}}</span>
28 <slot></slot>
29 </span>
30 </div>
31 <slot name="extension"></slot>
32 </div>
33</template>
34
35<script>
36import ZSlider from './child-components/z-slider'
37import ZKnob from './child-components/z-knob'
38export default {
39 name: 'z-spot',
40 props: {
41 distance: {
42 type: Number,
43 default: 100
44 },
45 angle: {
46 type: Number,
47 default: 0
48 },
49 index: {
50 type: Number
51 },
52 size: {
53 type: String,
54 default: 'medium'
55 },
56 label: {
57 type: [String, Number]
58 },
59 labelPos: {
60 type: [String],
61 default: 'bottom'
62 },
63 imagePath: {
64 type: [String]
65 },
66 progress: {
67 type: [Number, Object],
68 default: 0
69 },
70 qty: {
71 type: [Number],
72 default: 0
73 },
74 unit: {
75 type: [String]
76 },
77 min: {
78 type: [Number],
79 default: 0
80 },
81 max: {
82 type: [Number],
83 default: 100
84 },
85 pos: {
86 type: [String]
87 },
88 slider: {
89 type: [Boolean],
90 default: false
91 },
92 button: {
93 type: [Boolean],
94 default: false
95 },
96 knob: {
97 type: [Boolean],
98 default: false
99 },
100 toView: {
101 type: [String, Object]
102 }
103 },
104 inject: ['view'],
105 components: {
106 ZSlider,
107 ZKnob
108 },
109 data () {
110 return {
111 componentType: this.$options.name,
112 zpos: {},
113 innerpos: {},
114 extrainfo: '',
115 val: 0
116 }
117 },
118 computed: {
119 position () {
120 let component = {
121 componentType: this.componentType,
122 distance: this.$parent.componentType === 'z-list' ? this.distanceItem : this.distance,
123 angle: this.$parent.componentType === 'z-list' ? this.angleItem : this.angle,
124 size: this.size,
125 $parent: this.$parent
126 }
127 return this.$zircle.calcPosition(component)
128 },
129 angleItem () {
130 return (360 / this.$zircle.getNumberOfItemsInCurrentPage() * this.index) - 90
131 },
132 distanceItem () {
133 return this.$zircle.getNumberOfItemsInCurrentPage() === 1 ? 0 : this.distance
134 },
135 responsive () {
136 if (this.view === this.$zircle.getCurrentViewName()) {
137 // eslint-disable-next-line
138 this.zpos = this.styles
139 return true
140 } else {
141 return false
142 }
143 },
144 styles () {
145 var width = this.$zircle.getComponentWidth(this.size)
146 return {
147 main: {
148 width: width + 'px',
149 height: width + 'px',
150 margin: -(width / 2) + 'px 0 0 ' + -(width / 2) + 'px',
151 transform: 'translate3d(' + this.position.X + 'px, ' + this.position.Y + 'px, 0px)'
152 },
153 plate: {
154 width: width + 15 + 'px',
155 height: width + 15 + 'px',
156 margin: -((width + 15) / 2) + 'px 0 0 ' + -((width + 15) / 2) + 'px'
157 }
158 }
159 },
160 classes () {
161 return {
162 'z-zoom-in-cursor': this.componentType === 'z-spot' && this.toView !== undefined,
163 primary: this.$parent.componentType !== 'z-list',
164 accent: this.$parent.componentType === 'z-list'
165 }
166 },
167 progressLabel () {
168 if (this.computedQty) {
169 let unit = ''
170 this.unit ? unit = this.unit : unit = ''
171 return this.qty + '' + unit
172 }
173 },
174 computedQty: {
175 get: function () {
176 return this.qty
177 },
178 set: function (newValue) {
179 // this.val = newValue
180 this.$emit('update:qty', newValue)
181 }
182 }
183 },
184 methods: {
185 pulse () {
186 let pulse = this.$refs.pulse
187 pulse.classList.add('pulse-animation')
188 pulse.addEventListener('animationend', function () {
189 pulse.classList.remove('pulse-animation')
190 }, false)
191 },
192 spotin () {
193 if (this.button === false && this.view === this.$zircle.getCurrentViewName() && this.toView) this.$refs.spot.classList.add('spot-animation')
194 },
195 spotout () {
196 if (this.button === false && this.view === this.$zircle.getCurrentViewName() && this.toView) this.$refs.spot.classList.remove('spot-animation')
197 },
198 move () {
199 if (this.toView) {
200 this.$zircle.setView(this.toView, {
201 position: {
202 X: this.position.Xabs,
203 Y: this.position.Yabs,
204 scale: this.position.scale,
205 Xi: this.position.Xi,
206 Yi: this.position.Yi,
207 scalei: this.position.scalei
208 }
209 })
210 }
211 }
212 },
213 mounted () {
214 this.zpos = this.styles
215 }
216}
217</script>