|
@@ -1,38 +1,99 @@
|
|
|
-import { createApp } from 'vue'
|
|
|
+import { createApp } from "vue";
|
|
|
import {
|
|
|
- ActionBar, ActionBarIcon, ActionBarButton, Divider, Popup, Overlay, Loading, Dialog, ContactCard, Form, AddressEdit,
|
|
|
- AddressList, Field, CellGroup, Cell, SwipeCell, Icon, Stepper, Card, Checkbox, CheckboxGroup, Button, Swipe, SwipeItem,
|
|
|
- PullRefresh, List, Tab, Tabs, SubmitBar, Toast, Skeleton, RadioGroup, Radio, NoticeBar, ActionSheet, Cascader, Col, Row,
|
|
|
- Slider, DatePicker, Switch, Calendar, Picker, Uploader, Tag, DropdownMenu, DropdownItem, Notify, ConfigProvider, NavBar,
|
|
|
- Area, Popover, Collapse, CollapseItem, PickerGroup, TimePicker, BackTop, Progress, Tabbar, TabbarItem, Search, FloatingBubble,
|
|
|
- TextEllipsis, Step, Steps, Sticky
|
|
|
-} from 'vant';
|
|
|
-import { Image as VanImage } from 'vant';
|
|
|
-import App from './App.vue'
|
|
|
-import store from './store'
|
|
|
-import router from './router'
|
|
|
-import 'lib-flexible/flexible'
|
|
|
-import 'vant/lib/index.css'; // 全局引入样式
|
|
|
-import '@vant/touch-emulator';
|
|
|
+ ActionBar,
|
|
|
+ ActionBarIcon,
|
|
|
+ ActionBarButton,
|
|
|
+ Divider,
|
|
|
+ Popup,
|
|
|
+ Overlay,
|
|
|
+ Loading,
|
|
|
+ Dialog,
|
|
|
+ ContactCard,
|
|
|
+ Form,
|
|
|
+ AddressEdit,
|
|
|
+ AddressList,
|
|
|
+ Field,
|
|
|
+ CellGroup,
|
|
|
+ Cell,
|
|
|
+ SwipeCell,
|
|
|
+ Icon,
|
|
|
+ Stepper,
|
|
|
+ Card,
|
|
|
+ Checkbox,
|
|
|
+ CheckboxGroup,
|
|
|
+ Button,
|
|
|
+ Swipe,
|
|
|
+ SwipeItem,
|
|
|
+ PullRefresh,
|
|
|
+ List,
|
|
|
+ Tab,
|
|
|
+ Tabs,
|
|
|
+ SubmitBar,
|
|
|
+ Toast,
|
|
|
+ Skeleton,
|
|
|
+ RadioGroup,
|
|
|
+ Radio,
|
|
|
+ NoticeBar,
|
|
|
+ ActionSheet,
|
|
|
+ Cascader,
|
|
|
+ Col,
|
|
|
+ Row,
|
|
|
+ Slider,
|
|
|
+ DatePicker,
|
|
|
+ Switch,
|
|
|
+ Calendar,
|
|
|
+ Picker,
|
|
|
+ Uploader,
|
|
|
+ Tag,
|
|
|
+ DropdownMenu,
|
|
|
+ DropdownItem,
|
|
|
+ Notify,
|
|
|
+ ConfigProvider,
|
|
|
+ NavBar,
|
|
|
+ Area,
|
|
|
+ Popover,
|
|
|
+ Collapse,
|
|
|
+ CollapseItem,
|
|
|
+ PickerGroup,
|
|
|
+ TimePicker,
|
|
|
+ BackTop,
|
|
|
+ Progress,
|
|
|
+ Tabbar,
|
|
|
+ TabbarItem,
|
|
|
+ Search,
|
|
|
+ FloatingBubble,
|
|
|
+ TextEllipsis,
|
|
|
+ Step,
|
|
|
+ Steps,
|
|
|
+ Sticky,
|
|
|
+ showConfirmDialog,
|
|
|
+} from "vant";
|
|
|
+import { Image as VanImage } from "vant";
|
|
|
+import App from "./App.vue";
|
|
|
+import store from "./store";
|
|
|
+import router from "./router";
|
|
|
+import "lib-flexible/flexible";
|
|
|
+import "vant/lib/index.css"; // 全局引入样式
|
|
|
+import "@vant/touch-emulator";
|
|
|
// 导入语言
|
|
|
-import i18n from './utils/i18n';
|
|
|
+import i18n from "./utils/i18n";
|
|
|
|
|
|
async function checkVersion() {
|
|
|
// 开发环境跳过检测
|
|
|
- if (process.env.NODE_ENV !== 'production') return;
|
|
|
+ if (process.env.NODE_ENV !== "production") return;
|
|
|
try {
|
|
|
// 添加时间戳避免 version.json 缓存
|
|
|
- const response = await fetch('/shenze/version.json?t=' + Date.now());
|
|
|
+ const response = await fetch("/shenze/version.json?t=" + Date.now());
|
|
|
const serverVersion = await response.json();
|
|
|
- const localVersion = localStorage.getItem('appVersion') || '';
|
|
|
+ const localVersion = localStorage.getItem("appVersion") || "";
|
|
|
|
|
|
if (serverVersion.version !== localVersion) {
|
|
|
showUpdateDialog(serverVersion.version); // 触发更新提示
|
|
|
} else if (!localVersion) {
|
|
|
- localStorage.setItem('appVersion', serverVersion.version);
|
|
|
+ localStorage.setItem("appVersion", serverVersion.version);
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- console.error('版本检测失败:', error);
|
|
|
+ console.error("版本检测失败:", error);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -46,52 +107,58 @@ function startVersionPolling() {
|
|
|
startVersionPolling();
|
|
|
|
|
|
function showUpdateDialog(newVersion) {
|
|
|
- Dialog.confirm({
|
|
|
- title: '版本更新提示',
|
|
|
- message: `检测到新版本 ${newVersion},是否立即刷新?`,
|
|
|
- confirmButtonText: '立即刷新',
|
|
|
- cancelButtonText: '稍后刷新',
|
|
|
- }).then(() => {
|
|
|
- localStorage.setItem('appVersion', newVersion);
|
|
|
- window.location.reload();
|
|
|
- }).catch(() => {
|
|
|
- // 用户取消
|
|
|
- console.log('用户推迟了更新');
|
|
|
- });
|
|
|
+ const { t } = i18n.global;
|
|
|
+ showConfirmDialog({
|
|
|
+ title: t("public.updateTips"),
|
|
|
+ message: t("public.checkUpdate") + newVersion,
|
|
|
+ confirmButtonText: t("public.resetNow"),
|
|
|
+ showCancelButton: false,
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ localStorage.setItem("appVersion", newVersion);
|
|
|
+ window.location.reload();
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ console.log("用户推迟了更新");
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// 注册Service Worker
|
|
|
-if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') {
|
|
|
- window.addEventListener('load', () => {
|
|
|
- navigator.serviceWorker.register('/shenze/sw.js').then(registration => {
|
|
|
- console.log('ServiceWorker 注册成功:', registration.scope);
|
|
|
+if ("serviceWorker" in navigator && process.env.NODE_ENV === "production") {
|
|
|
+ window.addEventListener("load", () => {
|
|
|
+ navigator.serviceWorker
|
|
|
+ .register("/shenze/sw.js")
|
|
|
+ .then((registration) => {
|
|
|
+ console.log("ServiceWorker 注册成功:", registration.scope);
|
|
|
|
|
|
- navigator.serviceWorker.addEventListener('controllerchange', () => {
|
|
|
- window.location.reload();
|
|
|
+ navigator.serviceWorker.addEventListener("controllerchange", () => {
|
|
|
+ window.location.reload();
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.log("ServiceWorker 注册失败:", error);
|
|
|
});
|
|
|
- }).catch(error => {
|
|
|
- console.log('ServiceWorker 注册失败:', error);
|
|
|
- });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 在应用初始化前执行检测
|
|
|
checkVersion();
|
|
|
|
|
|
-const app = createApp(App) // 创建实例
|
|
|
+const app = createApp(App); // 创建实例
|
|
|
// 全局过滤器
|
|
|
app.config.globalProperties.$filters = {
|
|
|
prefix(url) {
|
|
|
- if (url && url.startsWith('http')) {
|
|
|
- return url
|
|
|
+ if (url && url.startsWith("http")) {
|
|
|
+ return url;
|
|
|
} else {
|
|
|
- url = `http://backend-api-01.newbee.ltd${url}`
|
|
|
- return url
|
|
|
+ url = `http://backend-api-01.newbee.ltd${url}`;
|
|
|
+ return url;
|
|
|
}
|
|
|
- }
|
|
|
-}
|
|
|
+ },
|
|
|
+};
|
|
|
// Vant组件注册
|
|
|
-app.use(ActionBarButton)
|
|
|
+app
|
|
|
+ .use(ActionBarButton)
|
|
|
.use(ActionBarIcon)
|
|
|
.use(ActionBar)
|
|
|
.use(Divider)
|
|
@@ -157,11 +224,11 @@ app.use(ActionBarButton)
|
|
|
.use(TextEllipsis)
|
|
|
.use(Step)
|
|
|
.use(Steps)
|
|
|
- .use(Sticky)
|
|
|
+ .use(Sticky);
|
|
|
|
|
|
-app.use(router)
|
|
|
-app.use(store)
|
|
|
+app.use(router);
|
|
|
+app.use(store);
|
|
|
|
|
|
-app.use(i18n)
|
|
|
+app.use(i18n);
|
|
|
|
|
|
-app.mount('#app')
|
|
|
+app.mount("#app");
|