Skip to content

Commit

Permalink
feat: 优化侧边栏样式,优化脚本列表样式,新增脚本版本切换功能,优化脚本详情信息显示
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Aug 17, 2023
1 parent 6d29148 commit 678a133
Show file tree
Hide file tree
Showing 23 changed files with 653 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cSpell.words": ["ICVE", "ocsjs", "userscript", "userscripts"],
"cSpell.words": ["greasyfork", "ICVE", "ocsjs", "scriptcat", "userscript", "userscripts"],
"eslint.validate": ["javascript", "javascriptreact", "vue"],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ocs-desktop/app",
"version": "2.2.5",
"version": "2.3.0",
"description": "desktop for userscript",
"main": "./lib/index.js",
"types": "./lib/types.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export function createWindow() {
const win = new BrowserWindow({
title: 'ocs',
icon: path.resolve('./public/favicon.ico'),
minHeight: 600,
minWidth: 1000,
minHeight: 800,
minWidth: 1200,
center: true,
hasShadow: true,
autoHideMenuBar: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ export interface UserScripts {
info: any;
/** 是否为本地脚本 */
isLocalScript: boolean;
/** 是否为网络链接加载的脚本 */
isInternetLinkScript: boolean;
}
113 changes: 113 additions & 0 deletions packages/web/src/components/CommonSelector.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<template>
<div>
<template v-if="props.list.length === 0">
<a-empty description="暂无数据" />
</template>
<template v-else>
<template
v-for="(item, index) of props.list.slice((state.page - 1) * state.pageSize, state.page * state.pageSize)"
:key="index"
>
<div
class="item"
:class="{
selected: isSelected(item)
}"
@click="select(item)"
>
<slot
name="content"
:item="item"
>
{{ item.key }}
</slot>
</div>
</template>

<div class="d-flex justify-content-center">
<a-pagination
:total="props.list.length"
:show-size-changer="false"
:show-quick-jumper="true"
:show-total="true"
:hide-on-single-page="true"
:default-current="1"
:default-page-size="state.pageSize"
@change="(page) => (state.page = page)"
>
</a-pagination>
</div>

<div class="mt-3 float-end">
<a-space>
<span
v-if="props.multiple"
style="font-size: 12px"
class="text-secondary float-end"
>
共选中 {{ selected.length }} 个
</span>
<a-button
style="width: 100px"
type="primary"
@click="confirm"
>
确定
</a-button>
</a-space>
</div>
</template>
</div>
</template>

<script setup lang="ts" generic="Item extends {key: string} ">
import { Ref, ref, reactive } from 'vue';
const props = defineProps<{
list: Item[];
onSelect: (items: Item[]) => void;
multiple: boolean;
}>();
const selected = ref<Item[]>([]) as Ref<Item[]>;
const state = reactive({
page: 1,
pageSize: 8
});
function confirm() {
props.onSelect(selected.value);
}
function select(item: Item) {
if (props.multiple) {
const index = selected.value.findIndex((i) => i.key === item.key);
if (index === -1) {
selected.value.push(item);
} else {
selected.value.splice(index, 1);
}
} else {
selected.value = [item];
}
}
function isSelected(item: Item) {
return selected.value.find((i) => i.key === item.key) !== undefined;
}
</script>

<style scoped lang="less">
.item {
border: 1px solid #e1e1e18c;
padding: 6px;
margin: 8px 0px;
border-radius: 4px;
cursor: pointer;
&.selected {
border: 1px solid #0d6efd8c;
}
}
</style>
2 changes: 1 addition & 1 deletion packages/web/src/components/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { Space } from '@arco-design/web-vue';
import { h, toRefs, useSlots } from 'vue';
const span = h('span');
interface IconProps {
theme?: 'outlined' | 'filled' | 'rounded' | 'sharp' | 'two-tone';
type: string;
theme?: 'outlined' | 'filled' | 'rounded' | 'sharp' | 'two-tone';
title?: string;
active?: boolean;
color?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
@mouseleave="selectedScript = 0"
@mouseover="selectedScript = script.id"
>
<!-- 如果有info则应该是网络搜索出来的脚本 -->
<div
v-if="script.info"
class="col-12"
>
<div class="user-script-name">
<a
target="_blank"
:href="script.info.url"
>
<span>{{ script.info.name }}</span>
</a>
<a-tooltip content="打开脚本源站">
<a
target="_blank"
:href="script.info.url"
>
<span>{{ script.info.name }}</span>
</a>
</a-tooltip>
</div>
<div
class="user-script-descriptions"
Expand Down Expand Up @@ -49,50 +52,61 @@
{{ script.info.description }}
</div>

<div class="user-script-infos">
<a-space size="mini">
<div class="row">
<div class="col-8">
<div class="user-script-infos">
<a-space size="mini">
<slot
:script="script"
name="infos"
></slot>

<a-tooltip content="最新版本">
<a-tag color="red">
v<b>{{ script.info.version }}</b>
</a-tag>
</a-tooltip>

<a-tooltip content="今日安装">
<a-tag color="blue">
⬇️<b>{{ script.info.daily_installs }}</b>
</a-tag>
</a-tooltip>

<a-tooltip content="总安装">
<a-tag color="green">
📦<b>{{ script.info.total_installs }}</b>
</a-tag>
</a-tooltip>

<a-tooltip content="评分">
<a-tag color="orange">
⭐<b>{{ script.info.ratings ? script.info.ratings.toFixed(1) : '无' }}</b>
</a-tag>
</a-tooltip>

<a-tag
v-if="script.info.create_time > 0"
title="创建时间"
>
{{ new Date(script.info.create_time).toLocaleDateString() }} 创建
</a-tag>
<a-tag
v-if="script.info.create_time > 0"
title="更新时间"
>
{{ getElapsedTime(script.info.create_time) }} 前更新
</a-tag>
</a-space>
</div>
</div>
<div class="col-4 user-script-actions">
<slot
name="actions"
:script="script"
name="infos"
></slot>

<a-tooltip content="今日安装">
<a-tag color="blue">
⬇️<b>{{ script.info.daily_installs }}</b>
</a-tag>
</a-tooltip>

<a-tooltip content="总安装">
<a-tag color="green">
📦<b>{{ script.info.total_installs }}</b>
</a-tag>
</a-tooltip>

<a-tooltip content="版本">
<a-tag color="red">
v<b>{{ script.info.version }}</b>
</a-tag>
</a-tooltip>

<a-tooltip content="评分">
<a-tag color="orange">
⭐<b>{{ script.info.ratings ? script.info.ratings.toFixed(1) : '无' }}</b>
</a-tag>
</a-tooltip>

<a-tag
v-if="script.info.createTime > 0"
title="创建时间"
>
{{ new Date(script.info.createTime).toLocaleDateString() }} 创建
</a-tag>
<a-tag
v-if="script.info.updateTime > 0"
title="更新时间"
>
{{ getElapsedTime(script.info.updateTime) }} 前更新
</a-tag>
</a-space>
:already-installed="isAlreadyInstalled(script)"
/>
</div>
</div>
</div>

Expand All @@ -109,22 +123,15 @@
</a>
</div>
</div>

<div class="user-script-actions">
<slot
name="actions"
:script="script"
:already-installed="isAlreadyInstalled(script)"
/>
</div>
</div>
</template>
</template>

<script setup lang="ts">
import { ref, toRefs } from 'vue';
import Icon from '../../components/Icon.vue';
import { store, StoreUserScript } from '../../store';
import { StoreUserScript } from '../store';
import { store } from '../store/index';
import Icon from './Icon.vue';
interface ScriptListProps {
scripts: StoreUserScript[];
Expand Down Expand Up @@ -243,8 +250,9 @@ function isAlreadyInstalled(sc: StoreUserScript) {
}
.user-script-actions {
position: relative;
transform: translateX(-100%);
display: flex;
justify-content: end;
align-items: center;
}
.ant-tag {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/Setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import { installExtensions } from '../utils/extension';
import { addScriptFromUrl } from '../utils/user-scripts';
import { ValidBrowser } from '@ocs-desktop/common/lib/src/interface';
import { ResourceLoader } from '../utils/resources.loader';
import { ResourceFile } from '../utils/apis';
import { ResourceFile } from '@ocs-desktop/common/src/api';
type Extension = ResourceFile & { installed?: boolean };
Expand Down
24 changes: 5 additions & 19 deletions packages/web/src/components/Title.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div class="title ps-2">
<span>
<span
style="cursor: pointer; -webkit-app-region: no-drag"
@click="shell.openExternal('https://docs.ocsjs.com')"
>
<img
width="18"
class="me-3"
Expand Down Expand Up @@ -158,7 +161,7 @@
</template>

<script setup lang="ts">
import { fetchRemoteNotify, date, about, clearBrowserCaches } from '../utils';
import { fetchRemoteNotify, date, about, checkBrowserCaches } from '../utils';
import { remote } from '../utils/remote';
import TitleLink from './TitleLink.vue';
import { Message, Modal } from '@arco-design/web-vue';
Expand All @@ -169,7 +172,6 @@ import { Folder, root } from '../fs/folder';
import { h } from 'vue';
import { FolderOptions, FolderType } from '../fs/interface';
import { Browser } from '../fs/browser';
import { SyncOutlined } from '@ant-design/icons-vue';
const { shell } = electron;
Expand Down Expand Up @@ -315,22 +317,6 @@ function reset() {
remote.app.call('relaunch');
remote.app.call('exit', 0);
}
async function checkBrowserCaches() {
const modal = Modal.info({
simple: false,
title: '正在计算浏览器缓存...',
footer: false,
maskClosable: false,
content: () => {
return h('div', [h(SyncOutlined, { spin: true }), '正在计算浏览器缓存...']);
}
});
const totalSize = await remote.methods.call('statisticFolderSize', store.paths.userDataDirsFolder);
modal.close();
clearBrowserCaches(totalSize);
}
</script>

<style scoped lang="less">
Expand Down
Loading

0 comments on commit 678a133

Please # to comment.