'text(单行文本)', 'textarea' => 'textarea(多行文本)', 'password' => 'password(密码文本)', 'option' => 'enum(枚举)', 'radio' => 'radio(单选按钮)', 'select' => 'select(下拉菜单)', 'select2' => 'select2(下拉菜单)', 'checkbox' => 'checkbox(复选框)', 'dialog' => 'dialog(对话框)', 'urd' => 'urd(权限对话框)', 'auto' => 'auto(宏控件)', 'calc' => 'calc(计算控件)', 'editor' => 'editor(编辑器)', 'date' => 'date(日期时间)', 'image' => 'image(单图上传)', 'images' => 'images(多图上传)', 'file' => 'file(文件上传)', 'files' => 'files(多文件上传)', 'address' => 'address(地址)', 'region' => 'region(行政区域)', 'location' => 'location(位置)', 'notification' => 'notification(通知)', 'sn' => 'sn(单据编号)', 'audit' => 'audit(审核状态)', 'custom' => 'custom(自定义)', ]; } public static function tr_text($setting, $param) { $title = $param['title']; $name = $param['name']; $tips = $param['tips']; $type = $param['type'] == '' ? 'text' : $param['type']; $items = $param['items']; $value = isset($setting[$name]) ? $setting[$name] : $param['value']; $str = '
'.$title.'
'; if ($type == 'text') { $str .= ''; } if ($type == 'textarea') { $str .= ''; } if ($type == 'radio') { foreach ($items as $item) { $str .= ''; } } if ($type == 'select') { $str .= ''; } if ($type == 'align') { $items = ['left' => '左', 'center' => '中', 'right' => '右']; $str .= ''; } $str .= '
'; return $str; } public static function tr_texts($setting, $params) { $str = ''; foreach ($params as $param) { $str .= static::tr_text($setting, $param); } return $str; } /** * 以下函数作用于字段添加/修改部分 */ public static function form_text($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '行表达式', 'name' => 'row_count', 'type' => 'textarea', 'tips' => '计算表达式,支持js语句'], ['title' => '列表达式', 'name' => 'cell_count', 'tips' => '列合计函数,支持: sum'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } public static function form_calc($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } public static function form_auto($setting = []) { $types = [ 'sys_date' => '当前日期,形如 1999-01-01', 'sys_date_cn' => '当前日期,形如 2009年1月1日', 'sys_date_cn_s1' => '当前日期,形如 2009年', 'sys_date_cn_s2' => '当前年份,形如 2009', 'sys_date_cn_s3' => '当前日期,形如 2009年1月', 'sys_date_cn_s4' => '当前日期,形如 1月1日', 'sys_time' => '当前时间', 'sys_datetime' => '当前日期+时间', 'sys_week' => '当前星期中的第几天,形如 星期一', 'sys_user_id' => '当前用户ID', 'sys_user_name' => '当前用户姓名', 'sys_user_name_date' => '当前用户姓名+日期', 'sys_user_name_datetime' => '当前用户姓名+日期+时间', 'sys_department_name' => '当前用户部门', 'sys_user_position' => '当前用户职位', 'sys_user_position_assist' => '当前用户辅助职位', 'sys_sql' => '来自sql查询语句', ]; $params = [ ['title' => '类型', 'name' => 'type', 'items' => $types, 'tips' => '', 'type' => 'select'], ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } public static function form_password($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } public static function form_textarea($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '高度', 'name' => 'height', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } public static function form_editor($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '高度', 'name' => 'height', 'tips' => 'px'], ['title' => '类型', 'name' => 'type', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '完整模式'], ['value' => 0, 'name' => '简洁模式']], 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => '', 'type' => 'textarea'], ]; return static::tr_texts($setting, $params); } public static function form_select($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '选项列表', 'name' => 'content', 'tips' => '格式:选项名称1|选项值1(回车换行)', 'type' => 'textarea'], ['title' => '查询键', 'name' => 'query_key', 'tips' => ''], ['title' => '查询值', 'name' => 'query_value', 'tips' => ''], ['title' => '查询参数', 'name' => 'query', 'tips' => '格式:name={name}', 'type' => 'textarea'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ['title' => '其他选项', 'name' => 'single', 'tips' => '', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '单选'], ['value' => 0, 'name' => '多选']]], ]; return static::tr_texts($setting, $params); } // 自定义 public static function form_custom($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '方法', 'name' => 'method', 'tips' => ''], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } // 地址选项 public static function form_address($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } // 行政区域 public static function form_region($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } // 流程状态 public static function form_audit($setting = []) { return static::form_region($setting); } // 单据编号 public static function form_sn($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], //['title' => '前缀', 'name' => 'prefix', 'tips' => '格式: DHD'], //['title' => '规则', 'name' => 'rule', 'tips' => '格式: {Y}{M}{D}'], //['title' => '序号', 'name' => 'length', 'tips' => '格式: 4'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } // 单选按钮 public static function form_radio($setting = []) { return static::form_select($setting); } // 多选按钮 public static function form_checkbox($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '选项列表', 'name' => 'content', 'tips' => '格式:选项名称1|选项值1(回车换行)', 'type' => 'textarea'], ['title' => '默认值', 'name' => 'default', 'tips' => ''], ]; return static::tr_texts($setting, $params); } // 图片上传 public static function form_image($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], //['title' => '路径', 'name' => 'path', 'tips' => '例如: calendar'], //['title' => '大小', 'name' => 'size', 'tips' => 'MB'], ]; return static::tr_texts($setting, $params); } // 多文件上传 public static function form_images($setting = []) { return static::form_image($setting); } // 文件上传 public static function form_file($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], //['title' => '格式', 'name' => 'type', 'tips' => '多个格式以,号分开,如:zip,rar,tar'], //['title' => '路径', 'name' => 'path', 'tips' => '例如: calendar'], //['title' => '大小', 'name' => 'size', 'tips' => 'MB'], ]; return static::tr_texts($setting, $params); } // 多文件上传 public static function form_files($setting = []) { return static::form_file($setting); } // 通知 public static function form_notification($setting = []) { $options = DB::table('option')->where('parent_id', 0)->pluck('name', 'value'); $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '数据源', 'name' => 'type', 'items' => $options, 'tips' => '', 'type' => 'select'], ['title' => '默认值', 'name' => 'default', 'tips' => '格式:选中值1,选中值2'], ['title' => '其他选项', 'name' => 'single', 'tips' => '', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '单选'], ['value' => 0, 'name' => '多选']]], ]; return static::tr_texts($setting, $params); } // 选项菜单 public static function form_option($setting = []) { $options = DB::table('option')->where('parent_id', 0)->pluck('name', 'value'); $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '数据源', 'name' => 'type', 'items' => $options, 'tips' => '', 'type' => 'select'], ['title' => '默认值', 'name' => 'default', 'tips' => "格式:选中值1,选中值2"], ['title' => '其他选项', 'name' => 'single', 'tips' => '', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '单选'], ['value' => 0, 'name' => '多选']]], ]; return static::tr_texts($setting, $params); } // 对话框 public static function form_dialog($setting = []) { $dialogs = ModuleService::dialogs(); $items = []; foreach($dialogs as $k => $v) { $items[$k] = $v['name']; } $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'css 样式: input-inline'], ['title' => '数据源', 'name' => 'type', 'items' => $items, 'tips' => '', 'type' => 'select'], ['title' => '查询键', 'name' => 'query_key', 'tips' => ''], ['title' => '查询值', 'name' => 'query_value', 'tips' => ''], ['title' => '查询参数', 'name' => 'query', 'tips' => '格式:name={name}', 'type' => 'textarea'], ['title' => '默认值', 'name' => 'default', 'tips' => "格式:选中值1,选中值2"], ['title' => '其他选项', 'name' => 'single', 'tips' => '', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '单选'], ['value' => 0, 'name' => '多选']]], ]; return static::tr_texts($setting, $params); } // select2插件 public static function form_select2($setting = []) { return static::form_select($setting); } // autocomplete插件 public static function form_autocomplete($setting = []) { return static::form_select($setting); } // 权限对话框 public static function form_urd($setting = []) { $params = [ ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => '格式:选中值1,选中值2'], ['title' => '其他选项', 'name' => 'single', 'tips' => '', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '单选'], ['value' => 0, 'name' => '多选']]], ]; return static::tr_texts($setting, $params); } // 日期 public static function form_date($setting = []) { $params = [ ['title' => '显示格式', 'name' => 'type', 'value' => 'Y-m-d H:i:s', 'tips' => '格式: Y-m-d H:i:s 表示: 2001-02-13 11:20:20'], ['title' => '数据格式', 'name' => 'save', 'items' => ['date' => '日期', 'u' => '时间戳'], 'tips' => '', 'type' => 'select'], ['title' => '最小日期', 'name' => 'min_date', 'tips' => '格式:2001-01-01,表示开始日期,或者以#开头的字段值'], ['title' => '最大日期', 'name' => 'max_date', 'tips' => '格式:2038-01-01,表示结束日期,或者以#开头的字段值'], ['title' => '对齐', 'name' => 'align', 'tips' => '', 'type' => 'align'], ['title' => '宽度', 'name' => 'width', 'tips' => 'px'], ['title' => '样式', 'name' => 'css', 'tips' => 'input-inline'], ['title' => '默认值', 'name' => 'default', 'tips' => '', 'type' => 'radio', 'items' => [['value' => 1, 'name' => '当前时间'], ['value' => 0, 'name' => '空']]], ]; return static::tr_texts($setting, $params); } // 字段扩展设置 public static function content_field($field) { // 配置 if (is_string($field['setting'])) { $setting = empty($field['setting']) ? [] : json_decode($field['setting'], true); } else { $setting = $field['setting']; } $attribute = $field['attribute']; if ($field['data_type']) { if ($field['type']) { $name = $field['table'].'['.$field['field'].']'; $id = $field['table'].'_'.$field['field']; } else { $id = $field['table'].'_'.$field['field']; } } else { if ($field['type']) { $name = $field['table'].'['.$field['field'].']'; $id = $field['table'].'_'.$field['field']; } else { $id = $field['table'].'_'.$field['field']; } } $attribute['key'] = $field['table'].'.'.$field['field']; $attribute['class'][] = 'form-control'; $attribute['class'][] = 'input-sm'; if ($setting['css']) { $attribute['class'][] = $setting['css']; } $view = $field['view']; if ($view['width']) { $attribute['style'][] = 'width:'.$view['width'].'px'; $attribute['class'][] = 'input-inline'; } if ($setting['height']) { $attribute['style'][] = 'height:'.$setting['height'].'px'; } if ($field['validate']) { $attribute['validate'] = $field['validate']; } $attribute['autocomplete'] = 'off'; $attribute['id'] = $id; $attribute['name'] = $name; $field['attribute'] = $attribute; $field['setting'] = $setting; $field['auth_id'] = auth()->id(); return $field; } // 字段属性组合 public static function content_attribute($attributes) { foreach ($attributes as $k => $v) { if ($k == 'class') { $attributes[$k] = $k.'="'.join(' ', $v).'"'; } elseif ($k == 'style') { $attributes[$k] = $k.'="'.join(';', $v).'"'; } else { $attributes[$k] = $k.'="'.$v.'"'; } } return join(' ', $attributes); } /** * 以下函数作用于发布内容部分 */ public static function content_custom($field, $content = '') { if ($field['is_show'] == 0) { $content = '
'; } else { $content = '
'.$content.'
'; } return $content; } public static function content_text($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $type = $field['is_hide'] == 0 ? 'text' : 'hidden'; if ($field['is_read'] == 1 && $field['is_hide'] == 1) { return ''; } if ($field['is_read']) { $field['attribute']['readonly'] = 'readonly'; } if ($field['is_write']) { $content = $content == '' ? $setting['default'] : $content; } if ($field['type'] == 'DECIMAL') { // 显示时才才格式化金额 if ($field['is_show']) { list($_, $len) = explode(',', $field['length']); $content = number_format(floatval($content), $len); } else { $content = floatval($content); } } return $field['is_show'] ? $content : ''; } public static function content_audit($field, $content = '', $row = []) { $field = static::content_field($field); $content = empty($content) ? '0' : $content; $option = option('flow.status', $content); if ($content == 2) { if ($row['id'] > 0) { $logs = DB::table('model_run_log') ->leftJoin('model_run', 'model_run.id', '=', 'model_run_log.run_id') ->where('model_run_log.option', 1) ->where('model_run_log.updated_id', 0) ->where('model_run.bill_id', $field['bill']['id']) ->where('model_run.data_id', $row['id']) ->pluck('model_run_log.run_name')->implode(','); $content = $option.' '.$logs; } } else { $content = $option; } if ($field['is_read']) { $field['attribute']['readonly'] = 'readonly'; } unset($field['attribute']['name']); return $field['is_show'] ? $content : ''; } public static function content_sn($field, $content = '') { $field = static::content_field($field); $bill = $field['bill']; if ($field['is_write']) { if ($content == '') { $make_sn = make_sn([ 'table' => $field['table'], 'bill_id' => $bill['id'], 'data' => $content, 'prefix' => $bill['sn_prefix'], 'rule' => $bill['sn_rule'], 'length' => $bill['sn_length'], ]); $content = $make_sn['new_value']; } } if ($field['is_auto'] || $field['is_read']) { $field['attribute']['readonly'] = 'readonly'; } return $field['is_show'] ? $content : ''; } public static function content_auto($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $t = isset($setting['type']) ? $setting['type'] : ''; $time = time(); $user = auth()->user(); $items = [ '{Y}' => date('Y', $time), '{M}' => date('m', $time), '{D}' => date('d', $time), '{H}' => date('H', $time), '{I}' => date('i', $time), '{S}' => date('s', $time), 'sys_date' => date('Y-m-d'), 'sys_user_name' => $user['name'], 'sys_user_name_datetime' => $user['name'].' '.date('Y-m-d H:i'), 'sys_department_name' => $user->department['name'], '{UR}' => $user->role['name'], '{UP}' => $user->position['name'], ]; if ($field['is_read']) { $field['attribute']['readonly'] = 'readonly'; } else { if ($field['is_show'] == 0) { $content = $items[$t]; //$content = $content == '' ? $items[$t] : $content; } if ($field['is_auto']) { $field['attribute']['readonly'] = 'readonly'; } } return $field['is_show'] ? $content : ''; } public static function content_address($field, $content = '') { $field = static::content_field($field); if ($field['is_show']) { return $content; } $_content = explode("\n", $content); $attribute = $field['attribute']; $id = $attribute['id']; $name = $attribute['name']; $class = ['form-control','input-sm']; $attr = 'class="'. join(' ', $class).'"'; $readonly = ''; if ($field['is_read']) { $readonly = 'readonly="readonly"'; } $str = '
'; $str .= ' '; $str .= ' '; $str .= ' '; $str .= '
'; if ($readonly == '') { $pcas = 'new pcas("'.$id.'_0", "'.$id.'_1", "'.$id.'_2", "'.$_content[0].'", "'.$_content[1].'", "'.$_content[2].'");'; $str .= ''; } return $str; } public static function content_region($field, $content = '', $row) { $field = static::content_field($field); $attribute = $field['attribute']; $id = $attribute['id']; if ($field['is_show']) { $ids = [$row['province_id'], $row['city_id'], $row['county_id']]; $content = DB::table('region')->whereIn('id', $ids)->pluck('name')->toArray(); return join(' ', $content); } $attr = 'class="'. join(' ', $attribute['class']).'"'; $readonly = ''; if ($field['is_read']) { $readonly = 'readonly="readonly"'; } $str = '
'; $str .= ' '; $str .= ' '; $str .= '
'; if ($readonly == '') { $pcas = 'new regionSelect("'.$id.'_0", "'.$id.'_1", "'.$id.'_2", "'.$row['province_id'].'", "'.$row['city_id'].'", "'.$row['county_id'].'");'; $str .= ''; } return $str; } public static function content_password($field, $content = '') { $field = static::content_field($field); if ($field['is_show']) { return ''; } if ($field['is_read']) { $field['attribute']['readonly'] = 'readonly'; } return ''; } public static function content_textarea($field, $content = '') { $field = static::content_field($field); if ($field['is_read']) { $field['attribute']['readonly'] = 'readonly'; } return $field['is_show'] ? nl2br($content) : ''; } public static function content_editor($field, $content = '') { $field = static::content_field($field); $attribute = $field['attribute']; if ($field['is_show']) { return $content; } return ueditor($attribute['name'], $content); } public static function content_notification($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $str = ' '; return $str; } public static function content_select($field, $content = '', $row = []) { $field = static::content_field($field); $setting = $field['setting']; $query = []; if ($setting['query']) { list($k, $v) = explode('=', $setting['query']); if (strpos($v, '$') === 0) { $v = substr($v, 1); if ($v == 'auth_id') { $query[$k] = $row[$v]; } else { $query[$k] = $row[$v]; } } else { $query[$k] = explode(',', $v); } } if ($field['is_show'] || $field['is_print']) { $str = []; if ($field['data_type']) { $model = DB::table($field['data_type'])->where('status', 1); foreach ($query as $k => $v) { if (is_array($v)) { $model->whereIn($k, $v); } else { $model->where($k, $v); } } $rows = $model->orderBy('sort', 'asc') ->pluck($field['data_field'], 'id'); foreach ($rows as $k => $v) { if ($k == $content) { $str[] = $v; } } return join(',', $str); } else { if (empty($setting['content'])) { return $content; } else { $select = explode("\n", $setting['content']); foreach ($select as $t) { $n = $v = $selected = ''; list($n, $v) = explode('|', $t); $v = is_null($v) ? trim($n) : trim($v); if ($v == $content) { $str[] = $n; } } return join(',', $str); } } } $hidden = ''; if ($field['is_read']) { $field['attribute']['disabled'] = 'disabled'; $hidden = ''; $field['attribute']['id'] = $field['attribute']['id'].'_select'; unset($field['attribute']['name']); } $str = $hidden.''; } public static function content_select2($field, $content = '', $row = []) { $field = static::content_field($field); $setting = $field['setting']; $related = $field['related']; $value = $content == 0 ? '' : $content; $dialog = ModuleService::dialogs($field['data_type']); $rows = []; $ids = explode(',', $value); if ($value && $dialog['model']) { $rows = $dialog['model']($ids)->pluck('name', 'id')->toArray(); } else { $rows = [$content => $content]; } if ($field['is_show']) { return join(',', $rows); } $options = []; foreach ($rows as $k => $v) { if ($related) { $options[] = ''; } else { $options[] = ''; } } $relations = explode(',', $setting['query']); $query = ['select2' => 'true']; $query['related'] = empty($related) ? 0 : 1; if ($relations) { foreach ($relations as $relation) { if ($relation) { list($k, $v) = explode('=', $relation); $query[$v] = $row[$k]; } } } $attribute = $field['attribute']; $css = ''; if($attribute['required']) { $css = 'input-select2-required'; } $attribute['class'][] = 'input-select2-custom'; $multi = (int)!$setting['single']; $id = $attribute['id']; $name = $attribute['name']; if ($field['is_read']) { $html[] = ''; return join("\n", $html); } else { $html[] = ''; $select2_options = [ 'placeholder' => '请选择'.$field['name'], 'width' => '100%', 'allowClear' => true, 'search_key' => $field['data_type'], 'containerCssClass' => $css, 'tags' => true, 'multiple' => $multi, 'ajaxParams' => $query, 'ajax' => [ 'url' => url($dialog['url']), ], ]; $html[] = ''; return join("\n", $html); } } public static function content_dialog($field, $content = '', $row = []) { $field = static::content_field($field); $setting = $field['setting']; $related = $field['related']; $value = $content == 0 ? '' : $content; if ($field['is_sub'] && $field['is_print']) { if (isset($field['_column'])) { return $row[$field['_column']]; } else { return $row[$field['field']]; } } $dialog = ModuleService::dialogs($setting['type']); $multi = (int)!$setting['single']; if ($related) { } else { $related['field'] = $field['field']; $related['table'] = $field['table']; } $attribute = $field['attribute']; $id = $attribute['id']; $name = $attribute['name']; $rows = ''; if ($value) { if ($field['type']) { $ids = explode(',', $value); $rows = $dialog['model']($ids)->implode(','); } else { $rows = $value; } } if ($field['is_print']) { return $rows; } if ($field['is_show']) { return ''.$rows; } if ($field['is_hide'] == 1) { return ''; } else { $width = '100%'; if ($field['is_read']) { if ($setting['css'] == 'input-inline') { $width = '153px'; } if ($setting['width']) { // $width = $setting['width'].'px'; } $html[] = '
'; } else { if ($setting['css'] == 'input-inline') { $width = '225px'; } if ($setting['width']) { // $width = $setting['width'].'px'; } $attribute = $field['attribute']; $css = $css2 = ''; if($attribute['required']) { $css = ' input-required'; $css2 = ' input-search-required'; } $query = []; if ($setting['query']) { list($k, $v) = explode('=', $setting['query']); if (strpos($v, '$') === 0) { $v = substr($v, 1); $query[$k] = $row[$v]; } else { $query[$k] = $v; } } $query['url'] = $dialog['url']; $query['title'] = $dialog['name']; $query['id'] = $related['field']; $query['form_id'] = $related['table']; $query['multi'] = $multi; $jq = ''; foreach ($query as $k => $v) { $jq .= ' data-'.$k.'="'. $v.'"'; } $html[] = '
'; $html[] = ''; $html[] = ''; } $html[] = '
'; return join("\n", $html); } } public static function content_urd($field, $content = '', $row = []) { $field = static::content_field($field); $setting = $field['setting']; $attribute = $field['attribute']; $attr_id = $attribute['id']; $attr_name = $attribute['name']; $name = str_replace('_id', '_name', $attr_name); $key_name = str_replace('_id', '_name', $attr_id); $v_id = $field['field']; $v_name = str_replace('_id', '_name', $v_id); $multi = (int)!$setting['single']; $params = [ 'multi' => $multi, 'prefix' => 1, 'name' => $key_name, 'title' => '', 'url' => 'index/api/dialog', 'id' => $attr_id, 'toggle' => 'dialog-view' ]; $jq = ''; foreach ($params as $key => $value) { $jq .= ' data-'.$key.'="'. $value.'"'; } if ($field['is_show']) { return $row[$v_name]; } else { if ($field['is_hide'] == 1) { return ''; } else { $width = '100%'; if ($field['is_read']) { if ($setting['css'] == 'input-inline') { $width = '153px'; } if ($setting['width']) { $width = $setting['width'].'px'; } $html[] = '
'; } else { if ($setting['css'] == 'input-inline') { $width = '225px'; } if ($setting['width']) { $width = $setting['width'].'px'; } $html[] = '
'; $html[] = '
'; $html[] = ''; $html[] = '
'; } $html[] = ''; $html[] = '
'; return join("\n", $html); } } } public static function content_option($field, $content = '', $row = []) { $field = static::content_field($field); $setting = $field['setting']; // 子表 if ($field['is_show']) { return option($setting['type'], $content); } // 新增时设置默认值 if (empty($row['id'])) { $content = $setting['default']; } if ($setting['single'] == 0) { $field['attribute']['multiple'] = 'multiple'; } if ($field['is_read']) { $field['attribute']['readonly'] = 'readonly'; $field['attribute']['onfocus'] = 'this.defaultIndex=this.selectedIndex;'; $field['attribute']['onchange'] = 'this.selectedIndex=this.defaultIndex;'; } $width = '100%'; if ($setting['css'] == 'input-inline') { $width = '153px'; } if ($setting['width']) { $width = $setting['width'].'px'; } $str = ''; } public static function content_date($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $type = isset($setting['type']) ? $setting['type'] : 'Y-m-d H:i:s'; $save = isset($setting['save']) ? $setting['save'] : 'date'; $time_sign = array( 'Y' => 'yyyy', 'y' => 'yy', 'm' => 'mm', 'm' => 'MM', 'M' => 'M', 'n' => 'm', 'd' => 'dd', 'j' => 'd', 'l' => 'DD', 'jS' => 'D', 'W' => 'W', 'H' => 'HH', 'h' => 'hh', 'G' => 'H', 'g' => 'h', 'i' => 'mm', 's' => 'ss', 'z' => 'z', 'c' => 'c', 'r' => 'r', 'a' => 'a', 't' => 't', 'A' => 'A' ); $time_format = strtr($type, $time_sign); $content = empty($content) ? ($setting['default'] == 1 ? date($type): '') : ($save == 'date' ? $content : date($type, $content)); if ($content == '0000-00-00' || $content == '0000-00-00 00:00:00') { $content = ''; } if ($content == '1900-01-01') { $content = ''; } if ($field['is_show']) { return $content; } $attribute = $field['attribute']; if ($field['is_read']) { $attribute['readonly'] = 'readonly'; } else { // 宏锁定 if ($field['is_auto']) { $attribute['readonly'] = 'readonly'; } else { $attribute['data-toggle'] = 'date'; $attribute['data-format'] = $time_format; $attribute['data-min_date'] = $setting['min_date']; $attribute['data-max_date'] = $setting['max_date']; } } return ''; } public static function content_radio($field, $content = '', $row, $permission) { $field = static::content_field($field); $setting = $field['setting']; $select = explode("\n", $setting['content']); $str = []; $w = $permission[$field['field']]['w'] == 1 ? '' : 'disabled="disabled"'; $disabled = $permission[$field['field']]['w'] == 1 ? '' : 'i-checks-disabled'; if ($field['is_print']) { foreach ($select as $t) { $n = $v = ''; list($n, $v) = explode('|', $t); $v = is_null($v) ? trim($n) : trim($v); if ($v == $content) { $str[] = $n; } } return join(',', $str); } $attribute = $field['attribute']; unset($attribute['class']); $id = $attribute['id']; $name = $attribute['name']; foreach ($select as $i => $t) { $n = $v = ''; list($n, $v) = explode('|', $t); $v = is_null($v) ? trim($n) : trim($v); $checked = $content == $v ? 'checked="checked"' : ''; $attribute['id'] = $id.'_'.$i; if ($field['is_show']) { $str[] = '
'; } else { $str[] = '
'; } } return join('', $str); } public static function content_checkbox($field, $content = '', $row = [], $permission = []) { $field = static::content_field($field); // 配置 $setting = $field['setting']; $default = $setting['default']; $content = is_null($content) ? $default : $content; $checkeds = []; $items = []; $values = explode(",", $content); if ($setting['type']) { $items = DB::table($setting['type'])->where('status', 1)->orderBy('sort', 'asc')->get(); } else { if (not_empty($setting['content'])) { $selects = explode("\n", $setting['content']); foreach ($selects as $select) { $n = $v = ''; list($n, $v) = explode('|', $select); $v = is_null($v) ? trim($n) : trim($v); $items[] = ['id' => $v, 'name' => $n]; } } else { $items[] = ['id' => 1, 'name' => $field['name']]; } } // 打印模式直接返回选中的值名称 if ($field['is_print']) { foreach ($items as $item) { if ($field['type']) { if (in_array($item['id'], $values)) { $checkeds[] = $item['name']; } } else { if ($row[$item['id']] == 1) { $checkeds[] = $item['name']; } } } return join(',', $checkeds); } $str = []; foreach ($items as $item) { // 存在字段 if ($field['type']) { $value = $v; $checked = in_array($v, $values) ? 'checked="checked"' : ''; $name = $field['table'].'['.$field['field'].']['.$v.']'; $key = $field['field']; } else { $value = 1; $checked = $row[$item['id']] == $value ? 'checked="checked"' : ''; $name = $field['table'].'['.$item['id'].']'; $key = $item['id']; } if ($field['is_show']) { $str[] = ''; } else { $w = $permission[$key]['w'] == 1 ? '' : 'disabled="disabled"'; $disabled = $permission[$key]['w'] == 1 ? '' : 'i-checks-disabled'; $str[] = ''; } } return join(' ', $str); } public static function content_image($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $attribute = $field['attribute']; $attribute['readonly'] = 'readonly'; $id = $attribute['id']; $name = $attribute['name']; if ($field['is_show']) { if (empty($content)) { $src = 'assets/images/nopic.jpg'; } else { $src = 'uploads/'.$content; } return '
'; } else { if (empty($content)) { $src = 'assets/images/nopic.jpg'; $close = ''; } else { $src = 'uploads/'.$content; $close = '×'; } $dialog = "mediaDialog('system/media/dialog', '".$name."', '".$id."', 0)"; $str = '
'.$close.'
'; } return $str; } public static function content_images($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $attribute = $field['attribute']; $id = $attribute['id']; $name = $attribute['name']; $attribute['readonly'] = 'readonly'; if ($field['is_show']) { $html = '
'; if (empty($content)) { $src = 'assets/images/nopic.jpg'; $html .= '
'; } else { $srcs = explode(',', $content); foreach($srcs as $src) { $html .= '
'; } } $html .= '
'; return $html; } else { $items = ''; if (empty($content)) { $src = 'assets/images/nopic.jpg'; $items .= '
'; } else { $srcs = explode("\n", $content); foreach($srcs as $src) { $items .= '
×
'; } } $dialog = "mediaDialog('system/media/dialog', '".$name."', '".$id."', 1)"; $html = '
'; $html .= '
'; $html .= $items; $html .= '
'; } return $html; } public static function content_location($field, $content = '', $row) { $field = static::content_field($field); $setting = $field['setting']; $attribute = $field['attribute']; $id = $attribute['id']; $name = $attribute['name']; $attribute['readonly'] = 'readonly'; if ($field['is_show']) { return ' '; } else { $str = '
'; } return $str; } public static function content_file($name, $content = '', $field = '') { // 配置 $setting = isset($field['setting']) ? json_decode($field['setting'], true) : $field; // 必填字段 $required = isset($field['not_null']) && $field['not_null'] ? ' required' : ''; $type = base64_encode($setting['type']); $size = (int)$setting['size']; return ' '; } public static function content_files($field, $content = '') { $field = static::content_field($field); $setting = $field['setting']; $attribute = $field['attribute']; $name = $attribute['name']; $key = $attribute['key']; $config = Setting::where('type', 'system')->pluck('value', 'key'); $input_id = $attribute['id']; $attachment = AttachmentService::edit($content, $key); if ($field['is_read'] || $field['is_show']) { $str = '
'; if (count((array)$attachment['rows'])) { foreach ($attachment['rows'] as $file) { $str .= '
'.$file['name'].' '; if (in_array($file['type'], ['pdf'])) { $str .= '[预览]'; } elseif (in_array($file['type'], ['jpg','png','gif','bmp'])) { // $str .= '[预览]'; $str .= '[预览]'; } $str .= '('.human_filesize($file['size']).') '.$file['created_by'].' '; $str .= '
'; } } $str .= '
'; $str .= ''; return $str; } else { //$qrcode = url('index/attachment/qrcode', ['path' => Request::module(), 'key' => $key, 'x-auth-token' => create_token(auth()->id(), 7)]); $str = '
'; /* */ $str .= ' 文件上传'; /* 扫码上传 */ $str .= '
'; if (count((array)$attachment['rows'])) { foreach ($attachment['rows'] as $file) { $str .= '
'.$file['name'].' ('.human_filesize($file['size']).')
'; } } $str .= '
'; if (count($attachment['draft'])) { foreach ($attachment['draft'] as $file) { $str .= '
! '.$file['name'].' ('.human_filesize($file['size']).')
'; } } $str .= '
'; /* $str .= ''; */ return $str; } } }