<template>
    <view class="page-content">
        <mx-nav-bar title="关于"/>
        <view class="fx-col fx-cen-cen py-80">
            <uv-image src="/static/logo.png" width="80" height="auto" mode="widthFix"/>
        </view>
        <uv-cell-group class="bg-white !flex-none">
            <uv-cell v-for="s in settings" v-bind="s" @click="s.handler()"/>
        </uv-cell-group>
    </view>
</template>

<script setup>
import {onMounted, reactive} from 'vue'
import {useTransfer} from "@/hooks/useTransfer";
import {useCacheStore} from "@/hooks/useCacheStore";
import {useEnvStore} from "@/hooks/useEnvStore";
import {confirmAsync} from "@/utils/uni-helper";
import {useUserStore} from "@/hooks/useUserStore";
import {sizeFormat} from "@/utils";

const {transferToProtocolUser, transferToProtocolPrivacy, transferToIndex, cleanAllTransferCacheData} = useTransfer()
const {getSize: getCacheSize, gcCache} = useCacheStore()
const {systemInfo} = useEnvStore()
const {LogoutPhysical, GetInfo} = useUserStore()

const settings = reactive([
    {
        title: '服务协议',
        icon: '/static/personal/icon-yonghuxieyi@2x.png',
        isLink: true,
        handler: () => transferToProtocolUser()
    },
    {
        title: '隐私政策',
        icon: '/static/personal/icon-yinxixieyi@2x.png',
        isLink: true,
        handler: () => transferToProtocolPrivacy()
    },
    {
        title: '清除缓存', //icon_cache
        icon: '/static/personal/icon_cache.png',
        rightIcon: 'reload',
        isLink: true,
        handler: () => {
            cleanAllTransferCacheData() // 清理页面大对象
            GetInfo() // GetInfo也会清除缓存，借机也更新一下用户信息
            calculateCacheSize()
        }
    },
    {
        title: '当前版本',
        icon: '/static/personal/icon-dangqianbanben@2x.png',
        value: systemInfo.value.appVersion,
        handler: () => {
        }
    },
    {
        title: '注销账号',
        icon: 'trash',
        isLink: true,
        handler: async () => {
            const msg = '是否注销账号，注销后卡号将不能再注册使用系统且永久失效。请谨慎操作！'
            await confirmAsync(msg)
            await LogoutPhysical()
            transferToIndex()
        }
    },
    {
        title: 'APP备案号',
        icon: 'empty-permission',
        value: '湘ICP备18012964号-8A',
        handler: () => {
        }
    },
    {
        title: '客服电话',
        icon: 'server-man',
        value: '400-1797-985',
        handler: () => {
        }
    }
])

onMounted(() => calculateCacheSize())

const calculateCacheSize = function () {
    gcCache()
    let size = getCacheSize()
    settings[2].value = sizeFormat(size)
}
</script>

<style scoped>
::v-deep .uv-cell__body {
    font-size: 16px;
    padding: 12px 15px;
}
</style>