import App from './App'
import { createSSRApp } from 'vue'
import store from '@/store'
import uView from "@/uni_modules/vk-uview-ui/index.js"
import getConfig from '@/config'
import {delayDel} from '@/libs/tools.js'
import vuexStore from "@/store/$u.mixin.js"

export function createApp() {
  const app = createSSRApp(App)
  app.config.productionTip = false
  app.use(store)
  app.use(uView)
  app.mixin(vuexStore)
  
  //延迟执行函数
  app.config.globalProperties.$delayDel = delayDel
  // 系统配置
  app.config.globalProperties.$config = function (key) {
	const theme = store.state.vuex_theme
  	return getConfig(theme)[key]
  }
  /**
   * 权限检查
   */
  app.config.globalProperties.$hasPermissions = function (value) {
   let isExist = false;
   let permissionsStr = store.state.vuex_userData.permCodes;
   if (permissionsStr == undefined || permissionsStr == null) {
    return false;
   }
   let has = permissionsStr.find(item => item == value)
   if (has) {isExist = true;}
   return isExist;
  }
  /*
  * 提示信息
  */ 
  app.config.globalProperties.toashMsg = function (title,duration) {
  	title = title == undefined ? "系统繁忙" : title;
  	uni.showToast({
  		title:title,
  		icon:'none',
  		duration: duration||4000
  	})
  }
  app.config.globalProperties.showLoading = function (title) {
  	title = title == undefined ? "正在加载..." : title;
  	uni.showLoading({
  		title:title,
  		mask: true
  	})
  }
  return {
    app
  }
}