初始化本地仓库
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import App from './App'
|
||||
import uViewPro from '@/uni_modules/uview-pro'
|
||||
import { applyAppTheme, getAppThemeMode } from '@/utils/theme.js'
|
||||
|
||||
const appThemeMixin = {
|
||||
data() {
|
||||
return {
|
||||
themeMode: getAppThemeMode()
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.__onScanappThemeChange = (themeMode) => {
|
||||
this.themeMode = themeMode
|
||||
}
|
||||
uni.$on('scanapp-theme-change', this.__onScanappThemeChange)
|
||||
},
|
||||
onShow() {
|
||||
this.themeMode = getAppThemeMode()
|
||||
applyAppTheme(this.themeMode)
|
||||
},
|
||||
beforeDestroy() {
|
||||
uni.$off('scanapp-theme-change', this.__onScanappThemeChange)
|
||||
},
|
||||
beforeUnmount() {
|
||||
uni.$off('scanapp-theme-change', this.__onScanappThemeChange)
|
||||
}
|
||||
}
|
||||
|
||||
applyAppTheme(getAppThemeMode())
|
||||
|
||||
// Android 原生 uni.showModal 的按钮顺序与 H5 不一致:确认按钮在左、取消按钮在右。
|
||||
// 仅交换显示文本并还原回调语义,避免逐个页面修改弹窗逻辑,也确保所有弹窗统一生效。
|
||||
// #ifdef APP-PLUS
|
||||
const installAndroidModalButtonOrderFix = () => {
|
||||
if (uni.__scanappAndroidModalButtonOrderFixed) return
|
||||
const systemInfo = uni.getSystemInfoSync ? uni.getSystemInfoSync() : {}
|
||||
if (systemInfo.platform !== 'android' || typeof uni.showModal !== 'function') return
|
||||
|
||||
const nativeShowModal = uni.showModal
|
||||
const normalizeResult = (result) => {
|
||||
if (!result || typeof result !== 'object') return result
|
||||
return {
|
||||
...result,
|
||||
confirm: Boolean(result.cancel),
|
||||
cancel: Boolean(result.confirm)
|
||||
}
|
||||
}
|
||||
|
||||
uni.showModal = (options = {}) => {
|
||||
if (options.showCancel === false) return nativeShowModal.call(uni, options)
|
||||
const confirmText = options.confirmText || '确定'
|
||||
const cancelText = options.cancelText || '取消'
|
||||
const nativeOptions = {
|
||||
...options,
|
||||
confirmText: cancelText,
|
||||
cancelText: confirmText,
|
||||
success: (result) => options.success?.(normalizeResult(result)),
|
||||
fail: (error) => options.fail?.(error),
|
||||
complete: (result) => options.complete?.(normalizeResult(result))
|
||||
}
|
||||
delete nativeOptions.__scanappNormalized
|
||||
const request = nativeShowModal.call(uni, nativeOptions)
|
||||
return request && typeof request.then === 'function' ? request.then(normalizeResult) : request
|
||||
}
|
||||
uni.__scanappAndroidModalButtonOrderFixed = true
|
||||
}
|
||||
installAndroidModalButtonOrderFix()
|
||||
// #endif
|
||||
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import './uni.promisify.adaptor'
|
||||
Vue.config.productionTip = false
|
||||
Vue.mixin(appThemeMixin)
|
||||
App.mpType = 'app'
|
||||
const app = new Vue({
|
||||
...App
|
||||
})
|
||||
app.$mount()
|
||||
// #endif
|
||||
|
||||
// #ifdef VUE3
|
||||
import {
|
||||
createSSRApp
|
||||
} from 'vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.mixin(appThemeMixin)
|
||||
app.use(uViewPro)
|
||||
return {
|
||||
app
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
Reference in New Issue
Block a user