|
|
@@ -180,6 +180,7 @@ struct NewIndex {
|
|
|
// WebDAV账户相关状态变量
|
|
|
@State webDavAccounts: WebDavAccount[] = []
|
|
|
private webdavManager: WebdavManager = WebdavManager.getInstance()
|
|
|
+ private _webDavLoading: boolean = false // 防止重复加载WebDAV账户的标志
|
|
|
|
|
|
/**
|
|
|
* 返回键处理逻辑:
|
|
|
@@ -560,7 +561,7 @@ struct NewIndex {
|
|
|
SegmentButton({ options: this.tabOptions, selectedIndexes: $tabSelectedIndexes })
|
|
|
}
|
|
|
.padding({ bottom:10 })
|
|
|
- .width('80%')
|
|
|
+ .width('90%')
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -719,7 +720,7 @@ struct NewIndex {
|
|
|
.fontColor([this.themeColor])
|
|
|
.effectStrategy(SymbolEffectStrategy.HIERARCHICAL)
|
|
|
.alignSelf(ItemAlign.Center)
|
|
|
- .margin({ left: 25 })
|
|
|
+ .margin({ left: 15 })
|
|
|
} else {
|
|
|
Image(item.img as Resource)
|
|
|
.height(22)
|
|
|
@@ -1180,9 +1181,9 @@ struct NewIndex {
|
|
|
Column() {
|
|
|
// 账户名称
|
|
|
Text(account.name)
|
|
|
- .margin({ left: 10, right: 20 })
|
|
|
+ .margin({ left: 8, right: 20 })
|
|
|
.fontSize(15)
|
|
|
- .fontColor(account.isActivate ? this.themeColor : $r('app.color.index_tab_font_color'))
|
|
|
+ .fontColor($r('app.color.text_color'))
|
|
|
.fontWeight(480)
|
|
|
.maxLines(1)
|
|
|
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
|
@@ -1191,19 +1192,18 @@ struct NewIndex {
|
|
|
// 账户类型标签
|
|
|
Text('WebDAV')
|
|
|
.fontSize(10)
|
|
|
- .fontColor(this.themeColor)
|
|
|
+ .fontColor($r('app.color.index_tab_font_color'))
|
|
|
.opacity(0.8)
|
|
|
- .backgroundColor($r('app.color.left_draw_bg'))
|
|
|
- .padding({ left: 6, right: 6, top: 2, bottom: 2 })
|
|
|
+ .padding({ left: 8,top: 2, bottom: 2 })
|
|
|
.borderRadius(3)
|
|
|
- .margin({ right: 8 })
|
|
|
|
|
|
// 服务器地址
|
|
|
- Text(`${account.isUseLocalHost ? account.localHost : account.host}:${account.port}`)
|
|
|
+ Text(`@${account.isUseLocalHost ? account.localHost : account.host}:${account.port}`)
|
|
|
.fontSize(12)
|
|
|
.fontColor($r('app.color.index_tab_font_color'))
|
|
|
.opacity(0.7)
|
|
|
.maxLines(1)
|
|
|
+ .padding({ right: 8, top: 2, bottom: 2 })
|
|
|
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
|
}
|
|
|
}
|
|
|
@@ -1211,14 +1211,6 @@ struct NewIndex {
|
|
|
|
|
|
Blank()
|
|
|
|
|
|
- // 激活状态
|
|
|
- if (account.isActivate) {
|
|
|
- Text('已激活')
|
|
|
- .fontSize(12)
|
|
|
- .fontColor(this.themeColor)
|
|
|
- .margin({ right: 10 })
|
|
|
- }
|
|
|
-
|
|
|
Image($r('app.media.arrow_right'))
|
|
|
.width(22)
|
|
|
.height(22)
|
|
|
@@ -1229,11 +1221,21 @@ struct NewIndex {
|
|
|
.height(55)
|
|
|
}
|
|
|
.backgroundColor(Color.Transparent)
|
|
|
- .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
|
|
|
+ .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.8 })
|
|
|
.onClick(() => {
|
|
|
console.info('heanup', '点击WebDAV账户:', account.name)
|
|
|
this.selectWebDavAccount(account)
|
|
|
})
|
|
|
+ .bindContextMenu(this.MenuDavBuilder(account), ResponseType.LongPress,
|
|
|
+ {
|
|
|
+ preview: MenuPreviewMode.IMAGE,
|
|
|
+ previewAnimationOptions: { scale: [0.8, 1.0] },
|
|
|
+ })
|
|
|
+ .bindContextMenu(this.MenuDavBuilder(account), ResponseType.RightClick,
|
|
|
+ {
|
|
|
+ preview: MenuPreviewMode.IMAGE,
|
|
|
+ previewAnimationOptions: { scale: [0.8, 1.0] },
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -1269,7 +1271,7 @@ struct NewIndex {
|
|
|
.clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
|
|
|
.onClick(() => {
|
|
|
console.info('heanup', '点击添加WebDAV账户')
|
|
|
- this.showAddWebDavAccountDialog()
|
|
|
+ this.showAddWebDavAccountDialog(false)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -1311,6 +1313,66 @@ struct NewIndex {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Builder
|
|
|
+ MenuDavBuilder(account: WebDavAccount) {
|
|
|
+ Menu(){
|
|
|
+ MenuItem({
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
|
|
|
+ content: '编辑'
|
|
|
+ })
|
|
|
+ .onClick(async() => {
|
|
|
+ this.showAddWebDavAccountDialog(true,account)
|
|
|
+ })
|
|
|
+
|
|
|
+ MenuItem({
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
|
|
|
+ content: '删除'
|
|
|
+ })
|
|
|
+ .onClick(async() => {
|
|
|
+ this.deleteWebDavAccount(account)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除WebDAV账户
|
|
|
+ */
|
|
|
+ async deleteWebDavAccount(account: WebDavAccount) {
|
|
|
+ try {
|
|
|
+ // 显示确认对话框
|
|
|
+ this.getUIContext().showAlertDialog({
|
|
|
+ title: '删除账户',
|
|
|
+ message: `确定要删除webdav账户"${account.name}"吗?`,
|
|
|
+ primaryButton: {
|
|
|
+ value: '取消',
|
|
|
+ action: () => {}
|
|
|
+ },
|
|
|
+ secondaryButton: {
|
|
|
+ value: '删除',
|
|
|
+ fontColor: Color.Red,
|
|
|
+ action: async () => {
|
|
|
+ try {
|
|
|
+ await this.webdavManager.removeAccount(account)
|
|
|
+ ToastUtil.showToast('WebDAV账户删除成功')
|
|
|
+ // 重新加载WebDAV账户列表
|
|
|
+ await this.loadWebDavAccounts()
|
|
|
+ LogUtil.info('heanup NewIndex', 'WebDAV账户删除成功:', account.name)
|
|
|
+ } catch (error) {
|
|
|
+ LogUtil.error('heanup NewIndex', `删除WebDAV账户失败: ${(error as Error).message}`)
|
|
|
+ ToastUtil.showToast('删除失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ LogUtil.error('heanup NewIndex', `删除WebDAV账户操作失败: ${(error as Error).message}`)
|
|
|
+ ToastUtil.showToast('操作失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除歌单
|
|
|
*/
|
|
|
@@ -1523,12 +1585,12 @@ struct NewIndex {
|
|
|
* 显示添加WebDAV账户对话框
|
|
|
*/
|
|
|
@State addDavDialogId:number = 1
|
|
|
- showAddWebDavAccountDialog() {
|
|
|
+ showAddWebDavAccountDialog(isEditMode?: boolean,account?: WebDavAccount) {
|
|
|
|
|
|
const node: FrameNode | null = this.getUIContext().getFrameNodeById("test_text") || null;
|
|
|
this.getUIContext().getPromptAction().openCustomDialog({
|
|
|
builder: () => {
|
|
|
- this.webDavAccountBuilder()
|
|
|
+ this.webDavAccountBuilder(isEditMode,account)
|
|
|
},
|
|
|
levelMode: LevelMode.EMBEDDED, // 启用页面级弹出框
|
|
|
levelUniqueId: node?.getUniqueId(), // 设置页面级弹出框所在页面的任意节点ID
|
|
|
@@ -1540,38 +1602,53 @@ struct NewIndex {
|
|
|
}
|
|
|
|
|
|
@Builder
|
|
|
- webDavAccountBuilder() {
|
|
|
+ webDavAccountBuilder(isEditMode?: boolean,account?: WebDavAccount) {
|
|
|
WebDavAccountDialog({
|
|
|
- isEditMode: false,
|
|
|
- account: new WebDavAccount(),
|
|
|
+ isEditMode: isEditMode,
|
|
|
+ account: account,
|
|
|
onCancel: () => {
|
|
|
// 取消添加
|
|
|
this.getUIContext().getPromptAction().closeCustomDialog(this.addDavDialogId)
|
|
|
},
|
|
|
onConfirm: (account: WebDavAccount) => {
|
|
|
this.getUIContext().getPromptAction().closeCustomDialog(this.addDavDialogId)
|
|
|
- this.webdavManager.insertAccount(
|
|
|
- account.name,
|
|
|
- account.host,
|
|
|
- account.localHost,
|
|
|
- account.isUseLocalHost,
|
|
|
- account.port,
|
|
|
- account.filepath,
|
|
|
- account.lyricFilePath,
|
|
|
- account.uploadFilePath,
|
|
|
- account.imageFilePath,
|
|
|
- account.account,
|
|
|
- account.password,
|
|
|
- account.enableHttps
|
|
|
- ).then(() => {
|
|
|
- ToastUtil.showToast('添加成功')
|
|
|
- // 重新加载WebDAV账户列表
|
|
|
- this.loadWebDavAccounts()
|
|
|
- LogUtil.info('heanup NewIndex', 'WebDAV账户添加成功:', account.name)
|
|
|
- }).catch((error: Error) => {
|
|
|
- LogUtil.error('heanup NewIndex', `添加WebDAV账户失败: ${error.message}`)
|
|
|
- ToastUtil.showToast('添加失败')
|
|
|
- })
|
|
|
+
|
|
|
+ if (isEditMode && account?.id) {
|
|
|
+ // 编辑模式:更新现有账户
|
|
|
+ this.webdavManager.editAccount(account).then(() => {
|
|
|
+ ToastUtil.showToast('修改成功')
|
|
|
+ // 重新加载WebDAV账户列表
|
|
|
+ this.loadWebDavAccounts()
|
|
|
+ LogUtil.info('heanup NewIndex', 'WebDAV账户修改成功:', account.name)
|
|
|
+ }).catch((error: Error) => {
|
|
|
+ LogUtil.error('heanup NewIndex', `修改WebDAV账户失败: ${error.message}`)
|
|
|
+ ToastUtil.showToast('修改失败')
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 添加模式:创建新账户
|
|
|
+ this.webdavManager.insertAccount(
|
|
|
+ account.name,
|
|
|
+ account.host,
|
|
|
+ account.localHost,
|
|
|
+ account.isUseLocalHost,
|
|
|
+ account.port,
|
|
|
+ account.filepath,
|
|
|
+ account.lyricFilePath,
|
|
|
+ account.uploadFilePath,
|
|
|
+ account.imageFilePath,
|
|
|
+ account.account,
|
|
|
+ account.password,
|
|
|
+ account.enableHttps
|
|
|
+ ).then(() => {
|
|
|
+ ToastUtil.showToast('添加成功')
|
|
|
+ // 重新加载WebDAV账户列表
|
|
|
+ this.loadWebDavAccounts()
|
|
|
+ LogUtil.info('heanup NewIndex', 'WebDAV账户添加成功:', account.name)
|
|
|
+ }).catch((error: Error) => {
|
|
|
+ LogUtil.error('heanup NewIndex', `添加WebDAV账户失败: ${error.message}`)
|
|
|
+ ToastUtil.showToast('添加失败')
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
});
|