|
|
|
@ -3,16 +3,48 @@ import formula from '../global/formula'; |
|
|
|
import Store from '../store'; |
|
|
|
import flatpickr from 'flatpickr' |
|
|
|
import dayjs from "dayjs"; |
|
|
|
import { update, datenum_local } from '../global/format'; |
|
|
|
import { setCellValue, setCellFormat } from '../global/api'; |
|
|
|
|
|
|
|
const fitFormat = (formatStr) => { |
|
|
|
let dateFormat = formatStr.replace(/y/g, 'Y'); |
|
|
|
dateFormat = dateFormat.replace(/d/g, 'D'); |
|
|
|
dateFormat = dateFormat.replace(/h/g, 'H'); |
|
|
|
|
|
|
|
dateFormat = dateFormat.replace(/上午\/下午/g, 'A'); |
|
|
|
dateFormat = dateFormat.replace(/上午/g, 'A'); |
|
|
|
dateFormat = dateFormat.replace(/下午/g, 'A'); |
|
|
|
|
|
|
|
dateFormat = dateFormat.replace(/AM\/PM/g, 'A'); |
|
|
|
dateFormat = dateFormat.replace(/AM/g, 'A'); |
|
|
|
dateFormat = dateFormat.replace(/PM/g, 'A'); |
|
|
|
dateFormat = dateFormat.replace(/\"/g, ''); |
|
|
|
|
|
|
|
if (dateFormat.includes('A')) { |
|
|
|
dateFormat = dateFormat.replace(/H/g, 'h'); |
|
|
|
} |
|
|
|
return dateFormat |
|
|
|
} |
|
|
|
|
|
|
|
const cellDatePickerCtrl = { |
|
|
|
cellFocus: function(r, c, value){ |
|
|
|
cellFocus: function (r, c, cell) { |
|
|
|
let row = Store.visibledatarow[r], |
|
|
|
row_pre = r == 0 ? 0 : Store.visibledatarow[r - 1]; |
|
|
|
let col = Store.visibledatacolumn[c], |
|
|
|
col_pre = c == 0 ? 0 : Store.visibledatacolumn[c - 1]; |
|
|
|
|
|
|
|
let margeset = menuButton.mergeborer(Store.flowdata, r, c); |
|
|
|
if(!!margeset){ |
|
|
|
let type = cell.ct.fa || 'YYYY-MM-DD'; |
|
|
|
let defaultDate = update('yyyy-MM-dd hh:mm:ss', cell.v); |
|
|
|
let dateFormat = fitFormat(type); |
|
|
|
let enableTime = false; |
|
|
|
let noCalendar = false; |
|
|
|
let enableSeconds = false; |
|
|
|
let time_24hr = true; |
|
|
|
let hasChineseTime = false; |
|
|
|
|
|
|
|
|
|
|
|
if (!!margeset) { |
|
|
|
row = margeset.row[1]; |
|
|
|
row_pre = margeset.row[0]; |
|
|
|
|
|
|
|
@ -27,23 +59,51 @@ const cellDatePickerCtrl = { |
|
|
|
top: row_pre |
|
|
|
}) |
|
|
|
|
|
|
|
flatpickr('#cellDatePickerBtn',{ |
|
|
|
dateFormat: "YYYY-MM-DD", |
|
|
|
if (/[上午下午]/.test(type)) { |
|
|
|
hasChineseTime = true |
|
|
|
} |
|
|
|
if (/[Hhms]/.test(dateFormat)) { |
|
|
|
enableTime = true; |
|
|
|
} |
|
|
|
if (!/[YMD]/.test(dateFormat)) { |
|
|
|
noCalendar = true; |
|
|
|
} |
|
|
|
if (/s/.test(dateFormat)) { |
|
|
|
enableSeconds = true; |
|
|
|
} |
|
|
|
if (/A/.test(dateFormat)) { |
|
|
|
time_24hr = false; |
|
|
|
} |
|
|
|
|
|
|
|
flatpickr('#luckysheet-input-box', { |
|
|
|
allowInput: false, |
|
|
|
defaultDate: dayjs(value).format('YYYY-MM-DD'), |
|
|
|
noCalendar, |
|
|
|
enableSeconds, |
|
|
|
enableTime, |
|
|
|
dateFormat, |
|
|
|
time_24hr, |
|
|
|
defaultDate, |
|
|
|
parseDate: (datestr, format) => { |
|
|
|
return dayjs(datestr).toDate(); |
|
|
|
}, |
|
|
|
formatDate: (date, format, locale) => { |
|
|
|
if (hasChineseTime) { |
|
|
|
return dayjs(date).format(format).replace('AM', '上午').replace('PM', '下午') |
|
|
|
} |
|
|
|
return dayjs(date).format(format); |
|
|
|
}, |
|
|
|
onChange: function (selectedDates, dateStr) { |
|
|
|
let currentVal = datenum_local(new Date(selectedDates)) |
|
|
|
$("#luckysheet-rich-text-editor").html(dateStr); |
|
|
|
formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); |
|
|
|
setCellValue(r, c, currentVal, { isRefresh: false }) |
|
|
|
setCellFormat(r, c, 'ct', cell.ct) |
|
|
|
if (!enableTime) { |
|
|
|
formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
$("#cellDatePickerBtn").click(); |
|
|
|
$("#luckysheet-input-box").click(); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|