Commit b680fa0e by liyijie

feat: 支持source的配置,判断association_record 还是 record

parent d24a60ff
...@@ -15,7 +15,7 @@ module TalltyImportExport ...@@ -15,7 +15,7 @@ module TalltyImportExport
# { key: 'user_code', name: '考核人工号' }, # { key: 'user_code', name: '考核人工号' },
# { key: 'user_department_name', name: '考核人部门' }, # { key: 'user_department_name', name: '考核人部门' },
# { key: 'state', name: '考核状态', method: :state_zh }, # { key: 'state', name: '考核状态', method: :state_zh },
# { key: 'score', name: '考核分' }, # { key: 'score', name: '考核分', source: true },
# ] # ]
# export_headers_result / headers # export_headers_result / headers
# key: 属性的英文名,可以支持user.name这样的方式 # key: 属性的英文名,可以支持user.name这样的方式
...@@ -28,6 +28,7 @@ module TalltyImportExport ...@@ -28,6 +28,7 @@ module TalltyImportExport
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格 # merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
# json: model_payload,代表存储在某一个列中 # json: model_payload,代表存储在某一个列中
# select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型 # select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
# source: true,如果source为true,代表从association_record 进行属性查询
def export_xlsx records, **options def export_xlsx records, **options
records = with_scope records records = with_scope records
...@@ -96,7 +97,10 @@ module TalltyImportExport ...@@ -96,7 +97,10 @@ module TalltyImportExport
records = @each_method.present? ? association_record.try_method(@each_method) : [association_record] records = @each_method.present? ? association_record.try_method(@each_method) : [association_record]
records.each do |record| records.each do |record|
index += 1 index += 1
_data = handle_data(record, header, index) _data = header[:source] ?
handle_data(association_record, header, index) :
handle_data(record, header, index)
if header[:merge].present? && last_row.present? && _data == last_row[col_index] if header[:merge].present? && last_row.present? && _data == last_row[col_index]
# 这里使用二维数组,每个数组里都是列内容相同的各行 # 这里使用二维数组,每个数组里都是列内容相同的各行
merge_column_hash[col_index] ||= [] merge_column_hash[col_index] ||= []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment