From b8d73e3fd3cd71ae8f51678de544e58801a14aa7 Mon Sep 17 00:00:00 2001 From: zhouoaoteng Date: Mon, 9 Dec 2024 10:38:32 +0800 Subject: [PATCH] add:index Signed-off-by: zhouoaoteng --- interfaces/kits/picker/picker.js | 17 ++++++++++++++++- .../kits/picker/src/picker_n_exporter.cpp | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 52951f6f..be202dd2 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -450,7 +450,8 @@ function getAudioPickerSelectResult(args) { function getDocumentPickerSaveResult(args) { let saveResult = { error: undefined, - data: undefined + data: undefined, + suffix: -1 }; if (args === undefined || args.resultCode === undefined) { saveResult.error = getErr(ErrCode.RESULT_ERROR); @@ -461,6 +462,9 @@ function getDocumentPickerSaveResult(args) { if (args.ability_params_stream) { saveResult.data = args.ability_params_stream; saveResult.error = args.resultCode; + if (args.userSuffixIndex) { + saveResult.suffix = args.userSuffixIndex; + } } } else if (args.resultCode === RESULT_CODE_ERROR) { saveResult.data = []; @@ -538,9 +542,17 @@ async function documentPickerSave(...args) { documentSaveResult = await modalPicker(documentSaveContext, documentSaveConfig, documentSaveWindow); saveResult = getDocumentPickerSaveResult(documentSaveResult); + this.suffixIndex = saveResult.suffix; return sendResult(args, saveResult); } +function getSelectedSuffixIndex() { + console.log('[picker] Get Selected Suffix Index start'); + let index = this.suffixIndex; + this.suffixIndex = -1; + console.log('[picker] Get Selected Suffix Index end: ' + index); + return index; +} async function sendResult(args, result) { try { if (result === undefined) { @@ -668,6 +680,8 @@ function DocumentViewPicker(...args) { this.save = documentPickerSave; this.context = ParseContext(args); this.window = parseWindow(args); + this.getSelectedIndex = getSelectedSuffixIndex; + this.suffixIndex = -1; } function AudioViewPicker(...args) { @@ -677,6 +691,7 @@ function AudioViewPicker(...args) { } export default { + getSelectedSuffixIndex, startModalPicker, ExtTypes : ExtTypes, PickerDetailType: PickerDetailType, diff --git a/interfaces/kits/picker/src/picker_n_exporter.cpp b/interfaces/kits/picker/src/picker_n_exporter.cpp index 92100f00..b84c617f 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -84,6 +84,22 @@ static void MakeResultWithArr(napi_env env, std::string key, napi_value &result, } } +static void MakeResultWithInt(napi_env env, std::string key, napi_value &result, + std::shared_ptr pickerCallBack) +{ + napi_status status = napi_generic_failure; + if (pickerCallBack->want.GetParams().HasParam(key.c_str())) { + const int32_t suffixindex = pickerCallBack->want.GetIntParam(key.c_str(), -1); + HILOG_INFO("Modal picker: %{public}s is %{public}d ", key.c_str(), suffixindex); + napi_value suffix = nullptr; + napi_create_int32(env, suffixindex, &suffix); + status = napi_set_named_property(env, result, key.c_str(), suffix); + if (status != napi_ok) { + HILOG_ERROR("Modal picker: napi_set_named_property suffix failed"); + } + } +} + static void MakeResultWithBool(napi_env env, std::string key, napi_value &result, std::shared_ptr pickerCallBack) { @@ -122,6 +138,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr