11<template >
22 <div
3- :class =" `go-captcha gc-wrapper ${config .showTheme ? 'gc-theme' : ' '}`"
3+ :class =" `go-captcha gc-wrapper ${localConfig .showTheme && 'gc-theme'}`"
44 :style =" wrapperStyles"
5+ v-show =" hasDisplayWrapperState"
56 >
67 <div class =" gc-header" >
7- <span >{{ config .title }}</span >
8- <img v-show =" data.thumb !== '' " :style =" thumbStyles" :src =" data .thumb" alt =" ... " />
8+ <span >{{ localConfig .title }}</span >
9+ <img v-show =" hasDisplayImageState " :style =" thumbStyles" :src =" localData .thumb" alt =" " />
910 </div >
1011 <div class =" gc-body" :style =" imageStyles" >
1112 <div class =" gc-loading" >
1213 <loading-icon />
1314 </div >
14- <img :style =" imageStyles" v-show =" data.image !== '' " class =" gc-picture" :src =" data .image" alt =" ... " @click =" handler.clickEvent" />
15+ <img :style =" imageStyles" v-show =" hasDisplayImageState " class =" gc-picture" :src =" localData .image" alt =" " @click =" handler.clickEvent" />
1516 <div class =" gc-dots" >
16- <div class =" gc-dot" v-for =" dot in dots.list" :key =" `${dot.key + '-' + dot.index}`" :style =" {
17- top: (dot.y - 11 ) + 'px',
18- left: (dot.x - 11 ) + 'px',
17+ <div class =" gc-dot" v-for =" dot in handler. dots.list" :key =" `${dot.key + '-' + dot.index}`" :style =" {
18+ top: (dot.y - ((localConfig.dotSize || 1)/2)-1 ) + 'px',
19+ left: (dot.x - ((localConfig.dotSize || 1)/2)-1 ) + 'px',
1920 }" >{{dot.index}}</div >
2021 </div >
2122 </div >
2223 <div class =" gc-footer" >
2324 <div class =" gc-icon-block gc-icon-block2" >
24- <close-icon :width =" 22 " :height =" 22 " @click =" handler.closeEvent" />
25- <refresh-icon :width =" 22 " :height =" 22 " @click =" handler.refreshEvent" />
25+ <close-icon :width =" localConfig.iconSize " :height =" localConfig.iconSize " @click =" handler.closeEvent" />
26+ <refresh-icon :width =" localConfig.iconSize " :height =" localConfig.iconSize " @click =" handler.refreshEvent" />
2627 </div >
2728 <div class =" gc-button-block" >
28- <button @click =" handler.confirmEvent" >{{ config .buttonText }}</button >
29+ <button :class = " !hasDisplayImageState && 'disabled' " @click =" handler.confirmEvent" >{{ localConfig .buttonText }}</button >
2930 </div >
3031 </div >
3132 </div >
3233</template >
3334
3435<script lang="ts" setup>
35- import {computed , ref , watch } from " vue"
36- import {ClickConfig , defaultConfig } from " ./meta/config" ;
37-
36+ import {computed , reactive , toRaw , watch } from " vue"
3837import CloseIcon from " ../../assets/icons/close-icon.vue" ;
38+
3939import RefreshIcon from " ../../assets/icons/refresh-icon.vue" ;
4040import LoadingIcon from " ../../assets/icons/loading-icon.vue" ;
4141
42+ import {ClickConfig , defaultConfig } from " ./meta/config" ;
4243import {ClickData } from " ./meta/data" ;
4344import {ClickEvent } from " ./meta/event" ;
45+ import {ClickExpose } from " ./meta/expose" ;
4446import {useHandler } from " ./hooks/handler" ;
4547
4648// @ts-ignore
@@ -57,26 +59,30 @@ const props = withDefaults(
5759 },
5860)
5961
60- const { data, events } = props ;
61- const config = ref ({
62- ... defaultConfig (),
63- ... props .config ,
64- })
65- watch (() => props .config , () => {
66- config .value = {
67- ... config .value ,
68- ... props .config
69- }
70- })
62+ const { data, events, config } = props ;
63+ const localData = reactive <ClickData >({... toRaw (data )})
64+ const localEvent = reactive <ClickEvent >({... toRaw (events )})
65+ const localConfig = reactive <ClickConfig >({... defaultConfig (), ... toRaw (config )})
66+
67+ watch (() => props .data , (newData , _ ) => {
68+ Object .assign (localData , newData )
69+ },{ deep: true });
7170
72- const handler = useHandler (data , events );
71+ watch (() => props .events , (newData , _ ) => {
72+ Object .assign (localEvent , newData )
73+ },{ deep: true })
7374
74- const hPadding = config .value .horizontalPadding || 0
75- const vPadding = config .value .verticalPadding || 0
76- const width = (config .value .width || 0 ) + ( hPadding * 2 ) + (config .value .showTheme ? 2 : 0 )
77- const dots = handler .dots
75+ watch (() => props .config , (newData , _ ) => {
76+ Object .assign (localConfig , newData )
77+ },{ deep: true })
78+
79+ const handler = useHandler (localData , localEvent );
7880
7981const wrapperStyles = computed (() => {
82+ const hPadding = localConfig .horizontalPadding || 0
83+ const vPadding = localConfig .verticalPadding || 0
84+ const width = (localConfig .width || 0 ) + ( hPadding * 2 ) + (localConfig .showTheme ? 2 : 0 )
85+
8086 return {
8187 width: width + " px" ,
8288 paddingLeft: hPadding + " px" ,
@@ -88,17 +94,32 @@ const wrapperStyles = computed(() => {
8894
8995const thumbStyles = computed (() => {
9096 return {
91- width: config . value .thumbWidth + " px" ,
92- height: config . value .thumbHeight + " px" ,
97+ width: localConfig .thumbWidth + " px" ,
98+ height: localConfig .thumbHeight + " px" ,
9399 }
94100})
95101
96102const imageStyles = computed (() => {
97103 return {
98- width: config . value .width + " px" ,
99- height: config . value .height + " px"
104+ width: localConfig .width + " px" ,
105+ height: localConfig .height + " px"
100106 }
101107})
108+
109+ const hasDisplayImageState = computed (() => {
110+ return localData .image != ' ' && localData .thumb != ' '
111+ })
112+
113+ const hasDisplayWrapperState = computed (() => {
114+ return (localConfig .width || 0 ) > 0 || (localConfig .height || 0 ) > 0
115+ })
116+
117+ defineExpose <ClickExpose >({
118+ reset: handler .resetData ,
119+ clear: handler .clearData ,
120+ refresh: handler .refreshEvent ,
121+ close: handler .closeEvent ,
122+ });
102123 </script >
103124
104125<style lang="less">
@@ -116,11 +137,11 @@ const imageStyles = computed(() => {
116137 .gc-dot {
117138 position : absolute ;
118139 z-index : 2 ;
119- width : 20 px ;
120- height : 20 px ;
140+ width : 22 px ;
141+ height : 22 px ;
121142 color : #cedffe ;
122143 background : #3e7cff ;
123- border : 2 px solid #f7f9fb ;
144+ border : 3 px solid #f7f9fb ;
124145 display :-webkit-box ;
125146 display :-webkit-flex ;
126147 display :-ms-flexbox ;
0 commit comments