diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 52951f6f4c4ef5f4d6c9013196211cb40cd8451d..be202dd2beeaa9635789b3f8b458626d6d244853 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 92100f00f97a9de624b736eec11aecf029ef6dd9..b84c617fe1c24be99ad23bdcb41444d62fafff71 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