<template>
  <ie-page bg-color="#F6F8FA">
    <ie-navbar title="调试" />
    <view class="p-20">
      <view class="h-20 my-20">用户数据：</view>
      <view class="bg-white">
        <textarea class="p-20 h-400 break-all" v-model="userJson" maxlength="-1"></textarea>
      </view>
    </view>
    <view class="m-20">
      <uv-button type="primary" @click="handleLoad">加载</uv-button>
    </view>
    <view class="p-20">
      <view class="h-20 my-20">app数据：</view>
      <view class="bg-white">
        <textarea class="p-20 h-400 break-all" v-model="appJson" maxlength="-1"></textarea>
      </view>
    </view>
    <view class="m-20">
      <uv-button type="primary" @click="handleLoad">加载</uv-button>
    </view>
    <view class="m-20">
      <uv-button type="success" @click="handleToHome">进入首页</uv-button>
    </view>
  </ie-page>
</template>

<script lang="ts" setup>
import { useUserStore } from '@/store/userStore';
import { useAppStore } from '@/store/appStore';

const userStore = useUserStore();
const appStore = useAppStore();

const userJson = ref('');
const appJson = ref('');

const handleLoad = () => {
  if (userJson.value) {
    try {
      userStore.loadFromLocal(userJson.value);
      uni.$ie.showToast('加载成功');
    } catch (error) {
      uni.$ie.showToast('加载失败');
    }
  }
}
const handleLoadApp = () => {
  if (appJson.value) {
    try {
      appStore.loadFromLocal(appJson.value);
      uni.$ie.showToast('加载成功');
    } catch (error) {
      uni.$ie.showToast('加载失败');
    }
  }
}

const handleToHome = () => {
  uni.reLaunch({
    url: '/pagesMain/pages/index/index',
    type: 'reLaunch'
  });
}
</script>

<style lang="scss"></style>