From e175f2ce83d2f50f32d3306a7555d1ae2900edc7 Mon Sep 17 00:00:00 2001 From: zhouoaoteng Date: Mon, 8 Jul 2024 22:51: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 175cd546..4956d22a 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -408,7 +408,8 @@ function getAudioPickerSelectResult(args) { function getDocumentPickerSaveResult(args) { let saveResult = { error: undefined, - data: undefined + data: undefined, + suffix: -1 }; if (args.resultCode === undefined) { saveResult.error = getErr(ErrCode.RESULT_ERROR); @@ -419,6 +420,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 = []; @@ -487,10 +491,18 @@ async function documentPickerSave(...args) { documentSaveResult = await modalPicker(args, documentSaveContext, documentSaveConfig); saveResult = getDocumentPickerSaveResult(documentSaveResult); + this.suffixIndex = saveResult.suffix; console.log('[picker] download save result: ' + JSON.stringify(saveResult)); 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) { @@ -602,6 +614,8 @@ function DocumentViewPicker(...args) { this.select = documentPickerSelect; this.save = documentPickerSave; this.context = ParseContext(args); + this.getSelectedIndex = getSelectedSuffixIndex; + this.suffixIndex = -1; } function AudioViewPicker(...args) { @@ -611,6 +625,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 c387e127..168193c2 100644 --- a/interfaces/kits/picker/src/picker_n_exporter.cpp +++ b/interfaces/kits/picker/src/picker_n_exporter.cpp @@ -79,6 +79,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 napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr pickerCallBack) { if (pickerCallBack == nullptr) { @@ -100,6 +116,7 @@ static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr