diff --git a/manifest.json b/manifest.json index 00a588b..e21ec36 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "querydash", "name": "QueryDash", - "version": "1.0.8", + "version": "1.0.9", "minAppVersion": "1.8.0", "description": "Refer to Dataview and add search, sorting, and pagination functions, just like Notion.", "author": "lwx", diff --git a/src/pages/GenerateColumns.tsx b/src/pages/GenerateColumns.tsx index 46d1db6..419a4a0 100644 --- a/src/pages/GenerateColumns.tsx +++ b/src/pages/GenerateColumns.tsx @@ -1,3 +1,8 @@ +import {TFile} from "obsidian"; +import React from "react"; +import {Typography} from "antd"; + +const {Text, Link} = Typography; export function formatValue( value: Record @@ -19,18 +24,70 @@ export function formatValue( } function formatObject(value: any) { - const type =value.type; - if(type==='file') { + const type = value.type; + if (type === 'file') { const fileName = value.path.split('/').pop().replace(/\.md$/, '') return {type: "link", path: value.path, display: fileName}; } if ("path" in value && "display" in value) { - // console.log("link value", value); + // console.log("link value", value); return {type: "link", path: value.path, display: value.display}; } if ("ts" in value) { - const display= window.moment(value.ts).format("YYYY-MM-DD HH:mm:ss"); + const display = window.moment(value.ts).format("YYYY-MM-DD HH:mm:ss"); return {type: "datetime", display: display}; } + if (value.url) { + return {type: "externalLink", path: value.url, display: value.display || value.url}; + } + + return {type: "text", display: value.display}; } + +export const ellipsisLink = (app: any, display: string, path: any) => { + return ( + { + const file = app.vault.getAbstractFileByPath(path); + if (file && file instanceof TFile) { + const leaf = app.workspace.getLeaf(); + leaf.openFile(file); + } + }}> + + {display} + + + ); +}; + +export const ellipsisDisplay = (display: string) => { + return ( + + {display?.toString()} + + ); +}; + +export const externalLink = (display: string, path: string) => { + // 在obsidian中打开外部链接 + return { + window.open(path, "_blank"); + }}> + + {display} + + ; +} + diff --git a/src/pages/tableview/TableView.tsx b/src/pages/tableview/TableView.tsx index f2aef0a..c6d689d 100644 --- a/src/pages/tableview/TableView.tsx +++ b/src/pages/tableview/TableView.tsx @@ -1,51 +1,16 @@ import type {ActionType, ProColumns} from '@ant-design/pro-components'; import {ProTable} from '@ant-design/pro-components'; -import {List, Tag, Typography} from 'antd'; +import {List, Tag} from 'antd'; import React, {useEffect, useRef} from 'react'; import {getAPI} from 'obsidian-dataview'; -import {formatValue} from "../GenerateColumns"; -import {App, TFile} from "obsidian"; +import {formatValue, ellipsisLink, ellipsisDisplay, externalLink} from "../GenerateColumns"; import {ViewProps} from "../../models/ViewProps"; const TableView: React.FC = ({app, source}) => { const [columns, setColumns] = React.useState[]>([]); - const dv = getAPI(app); - const {Text, Link} = Typography; - - - const ellipsisLink = (display: string, path: any) => { - return ( - { - const file = app.vault.getAbstractFileByPath(path); - if (file && file instanceof TFile) { - const leaf = app.workspace.getLeaf(); - leaf.openFile(file); - } - }}> - - {display} - - - ); - }; - - const ellipsisDisplay = (display: string) => { - return ( - - {display?.toString()} - - ); - }; const createColumns = (headers: string[]) => { let columns = []; @@ -66,14 +31,17 @@ const TableView: React.FC = ({app, source}) => { if (type === "datetime") { return ellipsisDisplay(display); } + if (type === "externalLink") { + return externalLink(display, path); + } if (type === "link") { - return ellipsisLink(display, path); + return ellipsisLink(app, display, path); } if (type === "array") { return display.map((v: any) => { if (typeof v === "object") { return - {ellipsisLink(v.display, v.path)} + {ellipsisLink(app, v.display, v.path)} } else { // tags @@ -138,6 +106,8 @@ const TableView: React.FC = ({app, source}) => { const queryResult = await dvApi.query(sql); + console.log("queryResult", queryResult); + const tableData: any = parseTableResult(queryResult.value, params); const headers: string[] = queryResult.value.headers; @@ -181,6 +151,8 @@ const TableView: React.FC = ({app, source}) => { request={async (params, sort, filter) => { // console.log('params:', params); const response = await executeTableQuery(dv, source, params); + + console.log("response", response); const {tableData, columns} = response; setColumns(columns);