{$content}
{$previewcontainer}
EOD;
}
/**
* 获取JS列数据
* @param string $field
* @param string $datatype
* @param string $extend
* @param array $itemArr
* @param array $fieldConfig
* @return string
*/
protected function getJsColumn($field, $datatype = '', $extend = '', $itemArr = [], $fieldConfig = [])
{
$lang = mb_ucfirst($field);
$formatter = '';
$fieldFormatterSuffix = $this->fieldFormatterSuffix;
foreach (['switch', 'image', 'file', 'tag', 'intDate'] as $index => $item) {
$property = $item . (in_array($item, ['image', 'file']) ? 'Field' : 'Suffix');
if (!isset($this->$property) || !$this->isMatchSuffix($field, $this->$property)) {
continue;
}
if ($item == 'intDate') {
$fieldFormatterSuffix[$field] = ['type' => ['int', 'bigint', 'timestamp'], 'name' => 'datetime'];
} else if (in_array($item, ['image', 'file'])) {
$fieldFormatterSuffix[$field] = $this->fieldFormatterSuffix[$item . (preg_match("/s$/i", $field) ? 's' : '')];
} else {
$fieldFormatterSuffix[$field] = $this->fieldFormatterSuffix[$item];
}
break;
}
foreach ($fieldFormatterSuffix as $k => $v) {
if (preg_match("/{$k}$/i", $field)) {
if (is_array($v)) {
if (in_array($datatype, $v['type'])) {
$formatter = $v['name'];
break;
}
} else {
$formatter = $v;
break;
}
}
}
$html = str_repeat(" ", 24) . "{field: '{$field}', title: __('{$lang}')";
if ($datatype == 'set') {
$formatter = 'label';
}
foreach ($itemArr as $k => &$v) {
if (substr($v, 0, 3) !== '__(') {
$v = "__('" . mb_ucfirst($v) . "')";
}
}
unset($v);
$searchList = json_encode($itemArr, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);
$searchList = str_replace(['":"', '"}', ')","'], ['":', '}', '),"'], $searchList);
if ($itemArr) {
$html .= ", searchList: " . $searchList;
}
// 文件、图片、权重等字段默认不加入搜索栏,字符串类型默认LIKE
$noSearchFiles = ['file$', 'files$', 'image$', 'images$', '^' . $this->sortField . '$'];
$noSearchFiles = array_merge($noSearchFiles, array_map(function ($item) {
return $item . '$';
}, $this->imageField), array_map(function ($item) {
return $item . '$';
}, $this->fileField));
if (preg_match("/" . implode('|', $noSearchFiles) . "/i", $field)) {
$html .= ", operate: false";
} elseif (in_array($datatype, ['varchar'])) {
$html .= ", operate: 'LIKE'";
}
if (in_array($datatype, ['date', 'datetime']) || $formatter === 'datetime') {
$html .= ", operate:'RANGE', addclass:'datetimerange', autocomplete:false";
} elseif (in_array($datatype, ['float', 'double', 'decimal'])) {
$html .= ", operate:'BETWEEN'";
}
if (in_array($datatype, ['set'])) {
$html .= ", operate:'FIND_IN_SET'";
}
if (isset($fieldConfig['CHARACTER_MAXIMUM_LENGTH']) && $fieldConfig['CHARACTER_MAXIMUM_LENGTH'] >= 255 && in_array($datatype, ['varchar']) && !$formatter) {
$formatter = 'content';
$html .= ", table: table, class: 'autocontent'";
}
if (in_array($formatter, ['image', 'images'])) {
$html .= ", events: Table.api.events.image";
}
if (in_array($formatter, ['toggle'])) {
$html .= ", table: table";
}
if ($itemArr && !$formatter) {
$formatter = 'normal';
}
if ($formatter) {
$html .= ", formatter: Table.api.formatter." . $formatter . "}";
} else {
$html .= "}";
}
return $html;
}
protected function getCamelizeName($uncamelized_words, $separator = '_')
{
$uncamelized_words = $separator . str_replace($separator, " ", strtolower($uncamelized_words));
return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator);
}
protected function getFieldListName($field)
{
return $this->getCamelizeName($field) . 'List';
}
}