(
datasheetId: string,
exportType: string,
option: {
view?: IViewProperty;
mirrorId?: string;
ignorePermission?: boolean;
} = {},
)
| 223 | }; |
| 224 | |
| 225 | export const exportDatasheetBase = async ( |
| 226 | datasheetId: string, |
| 227 | exportType: string, |
| 228 | option: { |
| 229 | view?: IViewProperty; |
| 230 | mirrorId?: string; |
| 231 | ignorePermission?: boolean; |
| 232 | } = {}, |
| 233 | ) => { |
| 234 | Message.info({ |
| 235 | content: t(Strings.start_download_loading), |
| 236 | }); |
| 237 | const { view, mirrorId, ignorePermission } = option; |
| 238 | const state = store.getState(); |
| 239 | const datasheet = Selectors.getDatasheet(state, datasheetId)!; |
| 240 | const permission = Selectors.getPermissions(state, datasheetId, undefined, mirrorId); |
| 241 | const fieldMap = Selectors.getFieldMap(state, datasheetId); |
| 242 | const fieldPermissionMap = Selectors.getFieldPermissionMap(state); |
| 243 | if (!datasheet || !fieldMap) { |
| 244 | return; |
| 245 | } |
| 246 | if (!ignorePermission && !permission.exportable) { |
| 247 | Modal.error({ |
| 248 | title: t(Strings.no_permission_tips_title), |
| 249 | content: t(Strings.no_permission_tips_description), |
| 250 | okText: t(Strings.refresh), |
| 251 | onOk: () => { |
| 252 | window.location.reload(); |
| 253 | }, |
| 254 | }); |
| 255 | return; |
| 256 | } |
| 257 | const { rows, cols } = getRowsAndCols(state, datasheet, view); |
| 258 | // Filter out fields without permissions |
| 259 | const visibleCols = cols.filter((col) => Selectors.getFieldRoleByFieldId(fieldPermissionMap, col.fieldId) !== ConfigConstant.Role.None); |
| 260 | |
| 261 | const Excel = await import('exceljs'); |
| 262 | const list: string[][] = []; |
| 263 | const runTask = runInTimeSlicing(function* () { |
| 264 | for (const row of rows) { |
| 265 | const item = visibleCols.map((col) => { |
| 266 | const cellValue = Selectors.getCellValue(state, datasheet.snapshot, row.recordId, col.fieldId); |
| 267 | const propsField = fieldMap[col.fieldId]!; |
| 268 | return Field.bindModel(propsField).cellValueToString(cellValue) || ''; |
| 269 | }); |
| 270 | list.push(item); |
| 271 | yield; |
| 272 | } |
| 273 | |
| 274 | const workbook = new Excel.Workbook(); |
| 275 | const nodeName = datasheet.name; |
| 276 | const viewName = view ? view.name : ConfigConstant.EXPORT_ALL_SHEET_NAME; |
| 277 | const tempWorksheet = workbook.addWorksheet(`${viewName}`); |
| 278 | tempWorksheet.columns = getColumnHeader(datasheet, visibleCols); |
| 279 | |
| 280 | // @ts-ignore |
| 281 | tempWorksheet.addRows(list); |
| 282 |
no test coverage detected