import { onLoad } from '@dcloudio/uni-app'
import { api_getSysNameAndLogo } from "@/http/api.js"
import { useLoginUserStore } from '@/stores/loginUser'
const loginUserStore = useLoginUserStore()

export function useSetTitle() {
  /**
   * 设置标题
   */
  const setTitle = () => {
    if(loginUserStore.loginUser.sysName){
      uni.setNavigationBarTitle({
        title: loginUserStore.loginUser.sysName //页面标题为页面顶部显示的文字
      });
    }else{
      api_getSysNameAndLogo().then(res => {
        let sysName = res.sysName || '';
        loginUserStore.setLoginUserTitle(sysName)
        uni.setNavigationBarTitle({
          title: sysName //页面标题为页面顶部显示的文字
        });
      })
    }
  }
  onLoad(() => {
    setTitle();
  })
}