Skip to content

Commit

Permalink
fix: fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed Jan 4, 2022
1 parent ad6f2ff commit 23cd7f9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
tar --transform='flags=r;s|sharelist-macos-x64|sharelist|' -zcvf sharelist_macos_amd64.tar.gz sharelist-macos-x64
tar --transform='flags=r;s|sharelist-linux-x64|sharelist|' -zcvf sharelist_linux_amd64.tar.gz sharelist-linux-x64
tar --transform='flags=r;s|sharelist-linux-arm64|sharelist|' -zcvf sharelist_linux_arm64.tar.gz sharelist-linux-arm64
tar --transform='flags=r;s|sharelist-linuxstatic-armv7|sharelist|' -zcvf sharelist_linux_armv7.tar.gz sharelist-linuxstatic-armv7
gh release create ${{ env.VERSION }} -n "${{ env.NOTE }}" -t "${{ env.VERSION }}" ${{ env.FILES }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
36 changes: 34 additions & 2 deletions packages/sharelist-web/src/hooks/useHooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { ref, reactive, Ref, UnwrapRef } from 'vue'
import { onBeforeRouteLeave, useRouter, RouteLocationRaw } from 'vue-router'
import { ref, reactive, Ref, UnwrapRef, onMounted, onUnmounted, getCurrentInstance } from 'vue'

export function safeOnMounted(hook: () => any): void {
const instance = getCurrentInstance()
console.log(instance)
if (instance?.isMounted || (instance as any)?._isMounted) {
hook()
} else {
onMounted(hook)
}
}

type ToggleValue = number | string | boolean | undefined

Expand Down Expand Up @@ -109,3 +118,26 @@ const useBoot = (cb: () => any): any => { }
// onMessage,
// }
// }

type useTitleOptions = {
restoreOnUnmount: boolean
}
export const useTitle = (title: string, options?: useTitleOptions): void => {
const lastTitle = ref('')

const run = () => {
lastTitle.value = document.title
document.title = title
}
safeOnMounted(() => {
run()
})

if (options?.restoreOnUnmount === true) {
onUnmounted(() => {
document.title = lastTitle.value
})
}

run()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ref, defineComponent, watch, onMounted } from 'vue'
import './index.less'
import Icon from '@/components/icon'
import { useStore } from 'vuex'
import { useToggle } from '@/hooks/useHooks'
import { useToggle, useTitle } from '@/hooks/useHooks'
// import Search from '../search'
import { Modal, InputSearch } from 'ant-design-vue'
import { RouterView, useRoute, useRouter } from 'vue-router'
Expand All @@ -17,6 +17,11 @@ export default defineComponent({

const { config } = useConfig()

watch(() => config.title, (nv) => {
useTitle(nv)
})


const onChangeLayout = () => {
commit('SET_LAYOUT', state.setting.layout == 'list' ? 'grid' : 'list')
}
Expand Down
9 changes: 8 additions & 1 deletion packages/sharelist-web/src/views/manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const { TabPane } = Tabs
import General from './partial/general'
import Drive from './partial/disk'
import Signin from './partial/signin'
import { useSetting } from '@/hooks/useSetting'
import { useSetting, useConfig } from '@/hooks/useSetting'
import useConfirm from '@/hooks/useConfirm'
import { useTitle } from '@/hooks/useHooks'

export default defineComponent({
setup() {
Expand All @@ -27,6 +28,12 @@ export default defineComponent({
const tabsSlots = {
tabBarExtraContent: () => <div style="cursor:pointer;font-size:12px;color:#666;" title="保存配置 / Save config" onClick={exportConfig} ><SaveOutlined style={{ fontSize: '15px', 'marginRight': '6px' }} />导出配置</div>
}
const { config } = useConfig()

watch(() => config.title, (nv) => {
useTitle(nv)
})

return () => (
<div class="setting">
<div class="settiing-header">
Expand Down
2 changes: 1 addition & 1 deletion packages/sharelist/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = app => {

router
.get('/api/setting', auth, controller.api.setting)
.get('/api/configs', auth, controller.api.config)
.get('/api/configs', controller.api.config)
.post('/api/setting', auth, controller.api.updateSetting)
.put('/api/cache/clear', auth, controller.api.clearCache)
.put('/api/reload', auth, controller.api.reload)
Expand Down
4 changes: 2 additions & 2 deletions packages/sharelist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "cross-env NODE_ENV=dev nodemon app.js -i ./cache",
"test": "echo \"Error: no test specified\" && exit 1",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
"pkg": "pkg . --output build/sharelist --targets linux-x64,linux-arm64,macos-x64,win-x64",
"pkg": "pkg . --output build/sharelist --targets linux-x64,linux-arm64,linuxstatic-armv7,macos-x64,win-x64 --public-packages '*'",
"pkg-local": "pkg . --output build/sharelist",
"release": "node ../../scripts/release.js --skipBuild --skipNpmPublish"
},
Expand Down Expand Up @@ -50,4 +50,4 @@
"./theme/**/*"
]
}
}
}

0 comments on commit 23cd7f9

Please sign in to comment.