This commit is contained in:
2026-05-09 15:15:57 +08:00
parent e6eea6d65e
commit c04ed8de6e
34 changed files with 5291 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
*.zip
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
+8
View File
@@ -0,0 +1,8 @@
{
"hash": "508d8a11",
"configHash": "7cd68b3a",
"lockfileHash": "d312325e",
"browserHash": "4fc384cb",
"optimized": {},
"chunks": {}
}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "module"
}
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>锋天气-知你冷暖</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+36
View File
@@ -0,0 +1,36 @@
{
"name": "weather",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.8",
"dsbridge": "^3.1.4",
"less": "^4.2.1",
"less-loader": "^12.2.0",
"pinia": "^2.2.8",
"pinia-plugin-persistedstate": "^4.1.3",
"qs": "^6.13.1",
"vant": "^4.9.9",
"vite-plugin-compression": "^0.5.1",
"vue": "^3.5.13",
"vue-router": "4"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/qs": "^6.9.17",
"@vitejs/plugin-vue": "^5.2.1",
"@vue/tsconfig": "^0.7.0",
"postcss-pxtorem": "^6.1.0",
"sass": "^1.81.1",
"sass-loader": "^16.0.3",
"typescript": "~5.6.2",
"vite": "^6.0.1",
"vue-tsc": "^2.1.10"
}
}
+2772
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -0,0 +1,9 @@
export default {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*'],
selectorBlackList: ['.norem']
}
}
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

+17
View File
@@ -0,0 +1,17 @@
<script setup lang="ts">
import { RouterView } from 'vue-router'
</script>
<template>
<div class="app-container">
<router-view>
</router-view>
</div>
</template>
<style scoped>
.app-container {
width: 100%;
min-height: 100vh;
}
</style>
Binary file not shown.

After

Width:  |  Height:  |  Size: 504 KiB

+5
View File
@@ -0,0 +1,5 @@
$color-primary: #165dff;
$color-success: #00b42a;
$color-warning: #fa981d;
$color-danger: #ff4d4f;
$color-default: #8c8c8c;
+3
View File
@@ -0,0 +1,3 @@
.primary-btn {
background-color: $color-primary;
}
View File
+3
View File
@@ -0,0 +1,3 @@
@mixin no-border() {
border: none;
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

+43
View File
@@ -0,0 +1,43 @@
<template>
<div class="common-header">
<van-nav-bar :title="title" left-arrow @click-left="handleBack" :border="false" :fixed="true" :safe-area-inset-top="true" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { useRouter } from 'vue-router'
export default defineComponent({
name: 'CommonHeader',
props: {
title: {
type: String,
default: ''
},
customBack: {
type: Function,
default: null
}
},
setup(props) {
const router = useRouter()
const handleBack = () => {
if (props.customBack) {
props.customBack()
} else {
router.back()
}
}
return {
handleBack
}
}
})
</script>
<style scoped lang="scss">
</style>
+7
View File
@@ -0,0 +1,7 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
+19
View File
@@ -0,0 +1,19 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import Vant from 'vant'
import 'vant/lib/index.css'
import store from './store'
import { useREM } from './utils/rem'
// 初始化rem
useREM()
const app = createApp(App)
app.use(router)
app.use(Vant)
app.use(store)
app.mount('#app')
+23
View File
@@ -0,0 +1,23 @@
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
{
path: '/',
redirect: '/home'
},
{
path: '/home',
name: 'home',
component: () => import('../views/home/index.vue'),
meta: {
keepAlive: true
}
}
]
const router = createRouter({
history: createWebHashHistory(),
routes
})
export default router
+10
View File
@@ -0,0 +1,10 @@
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const store = createPinia()
store.use(piniaPluginPersistedstate)
export default store
// 统一导出 useStore 方法
// export * from './user'
+79
View File
@@ -0,0 +1,79 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
.card {
padding: 2em;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
+25
View File
@@ -0,0 +1,25 @@
import type { ToastOptions } from 'vant'
declare global {
interface Window {
$toast: {
success(message: string, options?: ToastOptions): void
error(message: string, options?: ToastOptions): void
warning(message: string, options?: ToastOptions): void
info(message: string, options?: ToastOptions): void
loading(message?: string, options?: ToastOptions): void
}
}
}
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$toast: {
success(message: string, options?: ToastOptions): void
error(message: string, options?: ToastOptions): void
warning(message: string, options?: ToastOptions): void
info(message: string, options?: ToastOptions): void
loading(message?: string, options?: ToastOptions): void
}
}
}
+13
View File
@@ -0,0 +1,13 @@
// rem 适配
export const useREM = () => {
const baseSize = 75 // 基准大小,注意这里改为75
function setRem() {
const scale = document.documentElement.clientWidth / 750 // 设计稿宽度改为750
document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px'
}
setRem() // 初始化
window.onresize = () => {
setRem()
}
}
+344
View File
@@ -0,0 +1,344 @@
<template>
<div class="weather-app">
<div class="weather-header">
<i class="fas fa-cloud-sun"></i>
<span class="weather-title">锋天气</span>
</div>
<div class="weather-grid">
<div v-for="city in cities" :key="city.prefix" class="weather-container">
<div class="weather-info">
<div class="primary-info">
<div class="weather-icon">
<i :class="getWeatherIcon(city.weatherData.condition)"></i>
</div>
<div class="temp-location">
<div class="temperature">{{ city.weatherData.temperature }}°</div>
<div class="location-group">
<div class="location">{{ city.weatherData.location }}</div>
<div class="condition">{{ city.weatherData.condition }}</div>
</div>
</div>
</div>
<div class="secondary-info">
<div class="info-item">
<i class="fas fa-map-marker-alt"></i>
<span>{{ city.weatherData.country }}</span>
</div>
<div class="info-item">
<i class="fas fa-clock"></i>
<span>更新于 {{ city.weatherData.lastUpdate }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
const CACHE_DURATION = 15 * 60 * 1000 // 15 minutes in milliseconds
const cities = ref([
{
prefix: 'ningbo',
url: 'https://api.seniverse.com/v3/weather/now.json?key=SMaPuMVF4IicVWOpa&location=WTQ3VZQP879N&language=zh-Hans&unit=c',
weatherData: {}
},
{
prefix: 'shenzhen',
url: 'https://api.seniverse.com/v3/weather/now.json?key=SMaPuMVF4IicVWOpa&location=WS10730EM8EV&language=zh-Hans&unit=c',
weatherData: {}
},
{
prefix: 'shaoxing',
url: 'https://api.seniverse.com/v3/weather/now.json?key=SMaPuMVF4IicVWOpa&location=WTMDXTK6STK4&language=zh-Hans&unit=c',
weatherData: {}
},
{
prefix: 'hangzhou',
url: 'https://api.seniverse.com/v3/weather/now.json?key=SMaPuMVF4IicVWOpa&location=WTMKQ069CCJ7&language=zh-Hans&unit=c',
weatherData: {}
},
{
prefix: 'jinhua',
url: 'https://api.seniverse.com/v3/weather/now.json?key=SMaPuMVF4IicVWOpa&location=WTJJ6TY7R0FK&language=zh-Hans&unit=c',
weatherData: {}
}
])
const fetchWeather = async (city) => {
try {
const response = await axios.get(city.url)
const weather = response.data.results[0]
const weatherData = {
location: weather.location.name,
country: weather.location.country,
condition: weather.now.text,
temperature: weather.now.temperature,
lastUpdate: new Date(weather.last_update).toLocaleString(),
timestamp: Date.now()
}
localStorage.setItem(city.prefix, JSON.stringify(weatherData))
city.weatherData = weatherData
} catch (error) {
console.error(`Error fetching ${city.prefix} weather data:`, error)
}
}
const fetchWeatherWithDelay = () => {
cities.value.forEach((city, index) => {
const cachedData = localStorage.getItem(city.prefix)
if (cachedData) {
const weatherData = JSON.parse(cachedData)
if (Date.now() - weatherData.timestamp < CACHE_DURATION) {
city.weatherData = weatherData
return
}
}
setTimeout(() => {
fetchWeather(city)
}, index * 1000)
})
}
const getWeatherIcon = (condition) => {
const iconMap = {
'晴': 'fas fa-sun',
'多云': 'fas fa-cloud-sun',
'阴': 'fas fa-cloud',
'雨': 'fas fa-cloud-rain',
'雪': 'fas fa-snowflake',
'雷': 'fas fa-bolt',
// 可以根据需要添加更多天气状况映射
}
return iconMap[condition] || 'fas fa-cloud'
}
onMounted(() => {
fetchWeatherWithDelay()
})
</script>
<style scoped>
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css');
.weather-header {
display: flex;
justify-content: center;
align-items: center;
gap: 12px;
margin-bottom: 30px;
padding-top: 20px;
}
.weather-header i {
font-size: 2rem;
color: #2c3e50;
}
.weather-title {
font-size: 2.2rem;
font-weight: 600;
color: #2c3e50;
letter-spacing: 2px;
}
.weather-grid {
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr;
gap: 20px;
padding: 16px;
}
.weather-container {
background: rgba(255, 255, 255, 0.95);
border-radius: 16px;
padding: 24px;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
min-width: 0;
}
.weather-container:hover {
transform: translateY(-5px);
box-shadow: 0 12px 25px rgba(0, 0, 0, 0.12);
}
.primary-info {
display: flex;
align-items: center;
gap: 20px;
margin-bottom: 16px;
padding-left: 60px;
}
.weather-icon {
font-size: 2.5rem;
color: #4a90e2;
min-width: 60px;
width: 60px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.temp-location {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
justify-content: center;
margin-left: 60px;
}
.temperature {
font-size: 2rem;
font-weight: 400;
color: #2c3e50;
line-height: 1.2;
margin-bottom: 8px;
}
.location-group {
display: flex;
flex-direction: column;
gap: 4px;
}
.location {
font-size: 1.1rem;
font-weight: 500;
color: #2c3e50;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: 1.2;
}
.condition {
font-size: 0.9rem;
color: #5d7290;
line-height: 1.2;
}
.secondary-info {
padding-top: 16px;
border-top: 1px solid rgba(0, 0, 0, 0.08);
display: flex;
flex-direction: column;
gap: 8px;
}
.info-item {
display: flex;
align-items: center;
gap: 8px;
color: #7f8c8d;
font-size: 0.85rem;
line-height: 1.2;
}
.info-item > span {
font-size: 20px;
}
.info-item i {
min-width: 16px;
text-align: center;
color: #95a5a6;
}
@media (max-width: 992px) {
.weather-grid {
max-width: 900px;
padding: 12px;
gap: 16px;
}
.weather-container {
padding: 20px;
}
.weather-icon {
min-width: 50px;
width: 50px;
height: 50px;
}
.primary-info {
gap: 16px;
}
}
@media (max-width: 768px) {
.weather-grid {
grid-template-columns: 1fr;
max-width: 600px;
}
.weather-container {
padding: 16px;
}
.weather-icon {
min-width: 45px;
width: 45px;
height: 45px;
font-size: 2rem;
}
.temperature {
font-size: 1.6rem;
margin-bottom: 6px;
}
.location {
font-size: 1rem;
}
}
@media (max-width: 480px) {
.weather-grid {
padding: 10px;
gap: 12px;
}
.weather-container {
padding: 14px;
}
.primary-info {
gap: 12px;
}
.weather-icon {
min-width: 40px;
width: 40px;
height: 40px;
font-size: 1.8rem;
}
.temperature {
font-size: 1.4rem;
margin-bottom: 4px;
}
.location {
font-size: 0.95rem;
}
.condition {
font-size: 0.85rem;
}
}
</style>
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
File diff suppressed because one or more lines are too long
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"types": ["vite/client"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [
{ "path": "./tsconfig.node.json" }
]
}
+10
View File
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
{"root":["./src/env.d.ts","./src/main.ts","./src/vite-env.d.ts","./src/router/index.ts","./src/store/index.ts","./src/types/global.d.ts","./src/utils/rem.ts","./src/app.vue","./src/components/commonheader.vue","./src/views/home/index.vue"],"version":"5.6.3"}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: import("vite").UserConfig;
export default _default;
+33
View File
@@ -0,0 +1,33 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import viteCompression from 'vite-plugin-compression';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
var __filename = fileURLToPath(import.meta.url);
var __dirname = dirname(__filename);
// https://vite.dev/config/
export default defineConfig({
plugins: [vue(), viteCompression()],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: "\n @import \"@/assets/scss/global.scss\";\n "
}
}
},
server: {
proxy: {
'/api': {
target: 'http://your-api-server.com', // 替换为你的实际后端地址
changeOrigin: true,
rewrite: function (path) { return path.replace(/^\/api/, ''); }
}
}
}
});
+37
View File
@@ -0,0 +1,37 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import viteCompression from 'vite-plugin-compression'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// https://vite.dev/config/
export default defineConfig({
plugins: [vue(), viteCompression()],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: `
@import "@/assets/scss/global.scss";
`
}
}
},
server: {
proxy: {
'/api': {
target: 'http://your-api-server.com', // 替换为你的实际后端地址
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})
+1723
View File
File diff suppressed because it is too large Load Diff