Browse Source

refactor: ♻️ 删除退出组件

pull/1/head
jiangx 3 years ago
parent
commit
011643802a
  1. 172
      src/base/Logout/Logout.vue
  2. 1
      src/base/Logout/chahao.svg
  3. 9
      src/components/PublicComponent/PublicComponent.vue
  4. 13
      src/composables/useHandleScreen.ts
  5. 50
      src/composables/useLogout.ts

172
src/base/Logout/Logout.vue

@ -1,172 +0,0 @@
<template>
<div v-if="modelValue" class="logout-container">
<div class="dialog-wrapper">
<p class="out-icon" @click="close">
<img src="./chahao.svg" class="close-icon" />
</p>
<input id="pwd" v-model="state.pwd" class="commons" placeholder="请输入密码" type="password" />
<p v-if="state.error" class="err-tips">密码错误</p>
<ul class="num-items">
<li v-for="item of state.num" :key="item" class="num-item" @click="handleClick(item)">
{{ item }}
</li>
<li class="num-item deletes" @click="deletes">
<img alt="" src="./chahao.svg" />
</li>
</ul>
<button class="close-browser commons" @click="closeBrowser">退出程序</button>
</div>
</div>
</template>
<script setup lang="ts">
import { watch, reactive, computed } from 'vue'
defineProps({
modelValue: Boolean
})
const emits = defineEmits(['bingo', 'close', 'update:modelValue'])
const state = reactive({
pwd: '',
error: false,
num: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
})
const MAX_LEN = 6
//
const generatePwd = computed(() => {
const date = new Date()
return `${date.getDate().toString().padStart(2, '0')}${date.getDay().toString().padStart(2, '0')}${(date.getMonth() + 1)
.toString()
.padStart(2, '0')}`
})
function closeBrowser() {
if (state.pwd === generatePwd.value) {
emits('bingo')
}
}
function close() {
emits('update:modelValue', false)
}
function deletes() {
state.pwd = state.pwd.substring(0, state.pwd.length - 1)
}
function handleClick(item: number) {
if (state.pwd.length >= MAX_LEN) {
return
}
state.pwd += item
}
watch(
() => state.pwd,
newVal => {
state.error = newVal.length === MAX_LEN && newVal !== generatePwd.value
}
)
</script>
<style lang="scss" scoped>
.logout-container {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 9999;
background-color: rgb(0 0 0 / 30%);
backdrop-filter: blur(20px);
animation-duration: 0.3s;
.dialog-wrapper {
position: fixed;
top: 50%;
left: 50%;
display: flex;
align-items: center;
width: 780px;
padding: 90px 0;
background-color: #fff;
border-radius: 20px;
transform: translate3d(-50%, -50%, 0);
flex-direction: column;
align-content: flex-start;
.out-icon {
position: absolute;
top: 20px;
right: 25px;
.close-icon {
width: 50px;
}
}
.err-tips {
position: absolute;
top: 166px;
left: 172px;
font-size: 14px;
color: #c03127;
font-weight: bolder;
}
.commons {
width: 500px;
height: 60px;
border: none;
border-radius: 60px;
outline: none;
}
#pwd {
padding-left: 30px;
margin-bottom: 45px;
font-size: 16px;
box-shadow: 0 5px 9px 0 rgb(90 90 90 / 20%);
}
.num-items {
display: grid;
grid-template-columns: repeat(3, 62px);
grid-template-rows: repeat(3, 62px);
gap: 45px 80px;
width: 350px;
margin: 0 auto;
margin-bottom: 45px;
.num-item {
font-size: 30px;
text-align: center;
color: black;
border-radius: 50%;
line-height: 62px;
&.deletes {
display: flex;
justify-content: center;
align-items: center;
}
&:hover {
color: #fff;
background-color: #aca8b3;
}
&:nth-child(10) {
grid-column-start: 2;
}
img {
width: 40px;
height: 40px;
}
}
}
.close-browser {
font-size: 22px;
color: #fff;
background-color: #aca8b3;
}
}
}
</style>

1
src/base/Logout/chahao.svg

@ -1 +0,0 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1558935211967" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1972" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16"><defs><style type="text/css"></style></defs><path d="M883.7 825L570.8 511.9 883.7 199c8.1-8.1 12.2-18.7 12.2-29.4 0-10.6-4.1-21.3-12.2-29.4a41.465 41.465 0 0 0-58.8 0L512 453.3 199.1 140.2a41.465 41.465 0 0 0-58.8 0 41.465 41.465 0 0 0 0 58.8l313.1 312.9L140.3 825a41.465 41.465 0 0 0 0 58.8c16.3 16.3 42.5 16.3 58.8 0L512 570.7l313.1 312.9c8.1 8.1 18.7 12.2 29.4 12.2 10.6 0 21.3-4.1 29.4-12.2 16.1-16.1 16.1-42.5-0.2-58.6z" p-id="1973" fill="#b8bfc3"></path></svg>

Before

Width:  |  Height:  |  Size: 797 B

9
src/components/PublicComponent/PublicComponent.vue

@ -3,9 +3,6 @@
<!-- 地图容器 -->
<Map @handle-go="handleGO" @handle-detail="handleDetail" />
<!-- 退出弹框 -->
<Logout v-model="logout" />
<!-- 倒计时返回首页提示 -->
<Transition enter-active-class="animate__animated animate__zoomIn" leave-active-class="animate__animated animate__zoomOut">
<AutoBackNotification v-if="showCountDownDialog" :title="title" :delay="isWallpaper ? toWallpaperTime : toIndexTime" />
@ -21,20 +18,16 @@ import { useHandleScreen } from '@/composables/useHandleScreen'
import { useInitMap } from '@/composables/useInitMap'
import Map from '@/components/Map/Map.vue'
const Logout = defineAsyncComponent(() => import('@/base/Logout/Logout.vue'))
const AutoBackNotification = defineAsyncComponent(() => import('@/base/AutoBackNotification/AutoBackNotification.vue'))
const router = useRouter()
const route = useRoute()
const store = useRootStore()
const { language, showSearch, showDetail } = storeToRefs(store)
const { checkHandleScreen, showCountDownDialog, title, toIndexTime, toWallpaperTime, isWallpaper, setLogout, resetClickNumber, logout } =
useHandleScreen(handleScreen)
const { checkHandleScreen, showCountDownDialog, title, toIndexTime, toWallpaperTime, isWallpaper } = useHandleScreen(handleScreen)
//
function handleScreen() {
setLogout(false)
resetClickNumber()
showSearch.value && store.SET_SHOW_SEARCH(false)
showDetail.value && store.SET_SHOW_DETAIL(false)
language.value !== 'zh' && store.SET_LANGUAGE('zh')

13
src/composables/useHandleScreen.ts

@ -2,7 +2,6 @@ import { ref, computed, onMounted, watch, toRefs } from 'vue'
import { useRootStore } from '@/store/root'
import { useRouter } from 'vue-router'
import { getBackTime } from '@/http/api/base'
import { useLogout } from '@/composables/useLogout'
export const useHandleScreen = (callback: () => void) => {
const MIN_TIME = 0
@ -12,9 +11,7 @@ export const useHandleScreen = (callback: () => void) => {
const router = useRouter()
const store = useRootStore()
const { device, nativeMethods, mapStatus } = toRefs(store)
const { logout, resetClickNumber, setLogout, addTotalClick } = useLogout()
const { nativeMethods, mapStatus } = toRefs(store)
const totalTime = ref<[number, number]>([60, 60]) //总时间
const toIndexTime = ref(60) //回首页的时间
@ -58,8 +55,7 @@ export const useHandleScreen = (callback: () => void) => {
//跳转屏保挂载到全局 供app使用
window.sleepToWallpaper = sleepToWallpaper
async function checkHandleScreen(e: TouchEvent) {
device.value.label === 'windows' && addTotalClick(e)
async function checkHandleScreen() {
toIndexTime.value = totalTime.value[0]
toWallpaperTime.value = totalTime.value[1]
@ -115,9 +111,6 @@ export const useHandleScreen = (callback: () => void) => {
totalTime,
toIndexTime,
toWallpaperTime,
logout,
checkHandleScreen,
resetClickNumber,
setLogout
checkHandleScreen
}
}

50
src/composables/useLogout.ts

@ -1,50 +0,0 @@
import { ref, nextTick, watch } from 'vue'
export const useLogout = () => {
const logout = ref(false)
const clickedNumberTotal = ref(0)
const timer = ref()
const MAX_NUMBER = 10
const DELAY_TIME = 10000
const SAFE_COORDINATES = 200
function resetClickNumber() {
clickedNumberTotal.value = 0
}
function setLogout(flag: boolean) {
logout.value = flag
}
//点击商场logo 达到最大次数显示退出框
function addTotalClick(e: TouchEvent) {
try {
const { clientX, clientY } = e.changedTouches[0]
const _clientX = parseInt(String(clientX), 10)
const _clientY = parseInt(String(clientY), 10)
if (_clientX >= 0 && _clientX <= SAFE_COORDINATES && _clientY >= 0 && _clientY <= SAFE_COORDINATES) {
clickedNumberTotal.value++
}
nextTick(() => {
if (clickedNumberTotal.value >= MAX_NUMBER) {
logout.value = true
resetClickNumber()
}
})
} catch (error) {
console.log(error)
}
}
watch(clickedNumberTotal, newVal => {
clearTimeout(timer.value)
timer.value = setTimeout(() => {
if (newVal !== 0) {
clearTimeout(timer.value)
resetClickNumber()
}
}, DELAY_TIME)
})
return { resetClickNumber, addTotalClick, setLogout, logout }
}
Loading…
Cancel
Save