Skip to content

Commit

Permalink
feat: 1.weather api
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Mar 6, 2023
1 parent 25ffb62 commit 8c039fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
18 changes: 11 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,21 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
this.app.customCss.readSnippets();
}

resizeHandle = debounce(() => LoggerUtil.log('resize'), 500, true);
resizeHandle = debounce(
() => {
// LoggerUtil.log('resize')
},
500,
true,
);

async customizeResize(): Promise<void> {
// 防抖
this.resizeHandle();
}

async customizeClick(evt: MouseEvent): Promise<void> {
LoggerUtil.log('customizeClick');
// LoggerUtil.log('customizeClick');
}

getMenus() {
Expand Down Expand Up @@ -576,10 +582,10 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
// 设置选项卡
this.addSettingTab(new AwesomeBrainSettingTab(this.app, this, this.pluginDataIO));
this.registerView(POMODORO_HISTORY_VIEW, leaf => {
if(!this.pomodoroHistoryView) {
this.pomodoroHistoryView = new PomodoroHistoryView(leaf, this)
if (!this.pomodoroHistoryView) {
this.pomodoroHistoryView = new PomodoroHistoryView(leaf, this);
}
return this.pomodoroHistoryView
return this.pomodoroHistoryView;
});
this.registerView(BROWSER_VIEW, leaf => new BrowserView(leaf, this, OpenUrl));

Expand Down Expand Up @@ -621,8 +627,6 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
// Remove listener when we unload
this.register(() => media.removeEventListener('change', callback));
this.registerDomEvent(activeDocument, 'selectionchange', async (e: MouseEvent) => {
console.log('selectionchange');

EditorUtil.changeToolbarPopover(e, SETTINGS.toolbar);
});
this.registerDomEvent(activeDocument, 'click', async (e: MouseEvent) => {
Expand Down
3 changes: 1 addition & 2 deletions src/ui/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ const calledFunctionHandler = e => {
};
onMounted(async () => {
window.removeEventListener(eventTypes.calledFunction, calledFunctionHandler);
LoggerUtil.log('toolbar onMounted');
window.addEventListener(eventTypes.calledFunction, calledFunctionHandler);
});
Expand All @@ -230,7 +229,7 @@ onUnmounted(() => {
});
onUpdated(() => {
LoggerUtil.log('Toolbar updated');
// LoggerUtil.log('Toolbar updated');
});
</script>

Expand Down
24 changes: 13 additions & 11 deletions src/utils/weather.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable */
// @ts-nocheck
// https://github.com/PKM-er/Blue-topaz-example/blob/1d196ba3802dc9d37e83d48a7ea974f8d5c538f1/88-Template/script/fetchhomepage.js#L194

import { request } from './request';
export async function getWeather(city) {
return '';
const key = 'dc0f31ac6f37484f88e3e7d45b84e403'; //尽量换成自己申请的key以免接口失效https://console.qweather.com
//尽量换成自己申请的key以免接口失效https://console.qweather.com
const key = 'dc0f31ac6f37484f88e3e7d45b84e403';
let locationId = '';
let windydesc = '';
if (city) {
Expand All @@ -14,6 +15,7 @@ export async function getWeather(city) {
city = location.name;
}
const weather = await getQWeather(locationId, key);
let today;
if (weather == '-1') {
return await getWWeather(city);
} else {
Expand All @@ -26,8 +28,8 @@ export async function getWeather(city) {
//小风
windydesc = '清风徐徐';
} else windydesc = '有' + today.windDirDay + '风出没,风力' + today.windScaleDay + '级';
const today = weather[0];
const desc = `${city} ${today.textDay}${today.tempMin}~${today.tempMax}${
today = weather[0];
const desc = `${city} ${today.textDay}, ${today.tempMin}~${today.tempMax}${
air.category
} ${windydesc}${today.moonPhase.replace(/[\u4e00-\u9fa5]/g, '')}`;
return desc;
Expand All @@ -45,7 +47,7 @@ async function getWWeather(city) {
}
// 和风天气入口获取天气信息
async function getQWeather(locationId, key) {
days = 1;
let days = 1;
const weatherUrl = `https://devapi.qweather.com/v7/weather/3d?location=${locationId}&key=${key}`;
const wUrl = new URL(weatherUrl);
const res = await request({
Expand Down Expand Up @@ -137,8 +139,8 @@ async function urlGet(url) {
const res = await request({
url: finalURL.href,
method: 'GET',
cache: 'no-cache',
headers: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json;charset=gb2312',
'User-Agent':