|
|
@@ -22,13 +22,16 @@ import { DialogHelper } from '@pura/harmony-dialog'
|
|
|
// @Entry
|
|
|
@Component
|
|
|
export struct ScanFilePage{
|
|
|
+ @StorageProp('mediaKuList') mediaKuList: Array<VideoItem> = []; //媒体库文件
|
|
|
@State rootPath:string = '' //音频根目录
|
|
|
@State lockPath:string = ''
|
|
|
@Consume isShowDrawer: boolean;
|
|
|
@Consume offsetX: number;
|
|
|
@State strText:string = ''
|
|
|
+ @State textVisi:Visibility=Visibility.Hidden
|
|
|
@State isStart:boolean = false
|
|
|
@State isStartCover:boolean = false
|
|
|
+ @State isStartSync:boolean = false
|
|
|
@State appName:string = ''
|
|
|
//lottie动画构建渲染上下文
|
|
|
private mainRenderingSettings: RenderingContextSettings = new RenderingContextSettings(true)
|
|
|
@@ -94,14 +97,19 @@ export struct ScanFilePage{
|
|
|
const eventData: emitter.EventData = {};
|
|
|
emitter.emit({ eventId: 101 }, eventData); // 发送视频打开广播事件
|
|
|
this.watchStatus(false)
|
|
|
- ToastUtil.showToast('扫描文件入库成功!')
|
|
|
if(isOnekey){
|
|
|
this.isStartCover = false
|
|
|
+ this.strText = '获取成功!'
|
|
|
}else{
|
|
|
- this.isStart = false
|
|
|
+ if(this.isStartSync){
|
|
|
+ this.isStartSync = false
|
|
|
+ this.strText = '校正数据成功!'
|
|
|
+ }else{
|
|
|
+ this.strText = '扫描文件入库成功!'
|
|
|
+ this.isStart = false
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- this.strText = ''
|
|
|
//结束动画
|
|
|
lottie.pause()
|
|
|
lottie.stop()
|
|
|
@@ -122,28 +130,17 @@ export struct ScanFilePage{
|
|
|
}
|
|
|
|
|
|
|
|
|
- // @State titleBarModel: TitleBar.Model = new TitleBar.Model()
|
|
|
- // .setTitleTextStyle(FontStyle.Normal)
|
|
|
- // .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
|
|
|
- // .setLeftIcon($r('app.media.left_back_white'))
|
|
|
- // .setTitleName("文件扫描")
|
|
|
- // .setTitleFontColor(Color.White)
|
|
|
- // .setTitleBarBackground(this.themeColor)
|
|
|
- // .setLeftTitleBackground(this.themeColor)
|
|
|
- // .setTitleBarBottomLineColor(this.themeColor)
|
|
|
- // .setOnLeftClickListener(() => {
|
|
|
- // router.back()
|
|
|
- //
|
|
|
- // })
|
|
|
initState(isOnekey:boolean){
|
|
|
-
|
|
|
+ this.textVisi = Visibility.Visible
|
|
|
this.initLottie(this.path,true)
|
|
|
if(isOnekey){
|
|
|
+ this.strText = '正在获取'
|
|
|
this.isStartCover = true
|
|
|
}else{
|
|
|
+ this.strText = Utility.resourceToString(getContext(this),$r('app.string.scaning'))
|
|
|
this.isStart = true
|
|
|
}
|
|
|
- this.strText = Utility.resourceToString(getContext(this),$r('app.string.scaning'))
|
|
|
+
|
|
|
lottie.play()
|
|
|
}
|
|
|
|
|
|
@@ -224,11 +221,13 @@ export struct ScanFilePage{
|
|
|
.transition(TransitionEffect.move(TransitionEdge.BOTTOM)
|
|
|
.animation({ duration: 380, curve: Curve.Ease,delay:30 }))
|
|
|
|
|
|
- // Text(this.strText)
|
|
|
- // .margin({ right: 20,top:20,bottom:20 })
|
|
|
- // .fontSize(16)
|
|
|
- // .fontColor(Color.Black)
|
|
|
- // .fontWeight(480)
|
|
|
+ Text(this.strText)
|
|
|
+ .height(50)
|
|
|
+ .margin({ right: 20 })
|
|
|
+ .fontSize(16)
|
|
|
+ .fontColor($r('app.color.text_color'))
|
|
|
+ .fontWeight(480)
|
|
|
+ .visibility(this.textVisi)
|
|
|
|
|
|
|
|
|
Column() {
|
|
|
@@ -274,6 +273,26 @@ export struct ScanFilePage{
|
|
|
// .width('100%')
|
|
|
.margin({ left:25,right: 25 ,top:20,bottom:20 })
|
|
|
|
|
|
+ Row() {
|
|
|
+
|
|
|
+
|
|
|
+ Image($r('app.media.selected'))
|
|
|
+ .width(16)
|
|
|
+ .height(16)
|
|
|
+ .fillColor(this.themeColor)
|
|
|
+ .margin({ left:10})
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
+ Text($r('app.string.sync_tips'))
|
|
|
+ .margin({ left: 10, right: 20 })
|
|
|
+ .fontSize(15)
|
|
|
+ .fontColor(Color.Gray)
|
|
|
+ .fontWeight(480)
|
|
|
+ .layoutWeight(1)
|
|
|
+
|
|
|
+ }
|
|
|
+ // .width('100%')
|
|
|
+ .margin({ left:25,right: 25 ,bottom:20 })
|
|
|
+
|
|
|
}
|
|
|
.width(this.currentBreakpoint !== BreakpointTypeEnum.SM?450:350)
|
|
|
.backgroundColor($r('app.color.index_background'))
|
|
|
@@ -284,16 +303,13 @@ export struct ScanFilePage{
|
|
|
.animation({ duration: 380, curve: Curve.Ease,delay:60 }))
|
|
|
|
|
|
Column() {
|
|
|
- Button(this.isStart?'正在扫描':$r('app.string.start_scan'), { type: ButtonType.Capsule, stateEffect: false })
|
|
|
+ Button($r('app.string.start_scan'), { type: ButtonType.Capsule, stateEffect: false })
|
|
|
|
|
|
.width(180)
|
|
|
.height(55)
|
|
|
.clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
|
|
|
.margin({ top: 20, bottom: 10 })
|
|
|
- .linearGradient({
|
|
|
- direction: GradientDirection.Right,
|
|
|
- colors: [['#ff37a0fc', 0.0], ['#67e667', 0.5], ['#f5856e', 1.0]]
|
|
|
- })
|
|
|
+ .backgroundColor(this.themeColor)
|
|
|
.enabled(this.isStart ?false:true)
|
|
|
.onClick(() => {
|
|
|
this.doOptimize(false)
|
|
|
@@ -301,15 +317,12 @@ export struct ScanFilePage{
|
|
|
})
|
|
|
.alignSelf(ItemAlign.Center)
|
|
|
|
|
|
- Button(this.isStartCover?'正在扫描':$r('app.string.onekey_cover'), { type: ButtonType.Capsule, stateEffect: false })
|
|
|
+ Button($r('app.string.onekey_cover'), { type: ButtonType.Capsule, stateEffect: false })
|
|
|
.width(180)
|
|
|
.height(55)
|
|
|
.clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
|
|
|
- .margin({ top: 10, bottom: 20 })
|
|
|
- .linearGradient({
|
|
|
- direction: GradientDirection.Right,
|
|
|
- colors: [['#ff37a0fc', 0.0], ['#67e667', 0.5], ['#f5856e', 1.0]]
|
|
|
- })
|
|
|
+ .margin({ top: 10, bottom: 10 })
|
|
|
+ .backgroundColor(this.themeColor)
|
|
|
.enabled(this.isStartCover ?false:true)
|
|
|
.onClick(() => {
|
|
|
if(PreferencesUtil.getStringSync('COVER_API','')===''){
|
|
|
@@ -321,6 +334,19 @@ export struct ScanFilePage{
|
|
|
})
|
|
|
.alignSelf(ItemAlign.Center)
|
|
|
|
|
|
+ Button($r('app.string.sync_data'), { type: ButtonType.Capsule, stateEffect: false })
|
|
|
+ .width(180)
|
|
|
+ .height(55)
|
|
|
+ .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
|
|
|
+ .margin({ top: 10, bottom: 20 })
|
|
|
+ .backgroundColor(this.themeColor)
|
|
|
+ .enabled(this.isStartSync ?false:true)
|
|
|
+ .onClick(() => {
|
|
|
+ this.doSyncData()
|
|
|
+
|
|
|
+ })
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
+
|
|
|
|
|
|
}
|
|
|
.transition(TransitionEffect.move(TransitionEdge.BOTTOM)
|
|
|
@@ -337,6 +363,24 @@ export struct ScanFilePage{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ doSyncData() {
|
|
|
+ this.watchStatus(true)
|
|
|
+ this.initLottie(this.path,true)
|
|
|
+ this.isStartSync = true
|
|
|
+ this.textVisi = Visibility.Visible
|
|
|
+ this.strText = Utility.resourceToString(getContext(this),$r('app.string.sync_dataing'))
|
|
|
+ lottie.play()
|
|
|
+ // 仅提取 filePath 列表
|
|
|
+ const filePaths = this.mediaKuList.map(item => item.filePath);
|
|
|
+ Logger.info('xiaozheng 校正数据开始 this.filePaths length= ' + filePaths.length)
|
|
|
+ const task2 = new taskpool.Task(syncDataTask, getContext(this), filePaths);
|
|
|
+ taskpool.execute(task2, taskpool.Priority.HIGH).then(()=>{
|
|
|
+ this.endScan(false)
|
|
|
+ }).catch((e:object)=>{
|
|
|
+ console.info("task2 catch e: " + e);
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
showTipsDialog() {
|
|
|
DialogHelper.showCustomContentDialog({
|
|
|
dialogId: 'tips',
|
|
|
@@ -395,6 +439,34 @@ export struct ScanFilePage{
|
|
|
|
|
|
|
|
|
|
|
|
+//扫描数据库校正对比数据是否真实存在,不存在在删除数据
|
|
|
+@Concurrent
|
|
|
+async function syncDataTask(context: Context, mediaKuList: Array<string>) {
|
|
|
+ const table: MediaTable = new MediaTable(context);
|
|
|
+ for (const item of mediaKuList) {
|
|
|
+ const filePath = item;
|
|
|
+ // 检查 filePath 是否存在
|
|
|
+ const exists:boolean = await FileUtil.accessSync(filePath);
|
|
|
+ // 如果 filePath 不存在,则删除数据库中的数据
|
|
|
+ if (!exists) {
|
|
|
+ table.getRdbStore(context, async (err:Error) => {
|
|
|
+ if (err) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Logger.info('xiaozheng 校正数据开始 this.exists = ' + exists+' filepath = ' +filePath)
|
|
|
+ await table.deleteDataFilePath(filePath, (result:boolean) => {
|
|
|
+ if(result){
|
|
|
+ Logger.info(`xiaozheng Deleted item success with filePath: ${filePath}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//扫描文件入库
|
|
|
@Concurrent
|
|
|
async function scanDirectoryTask(context: Context, dirPath: string, lockPath: string,cover_api:string) {
|
|
|
const stack: string[] = [dirPath];
|