title(admin_trans( 'admin.settings')) ->body( <<{$this->form()->render()} HTML ); } protected function form() { $distInfo = DistAdminDistributor::getInfo(); $form = new Form(); $form->tab('domain', function (Form $form) use ($distInfo) { //查分销商信息 $secondaryDomain = $distInfo->secondary_domain ? $distInfo->secondary_domain : ''; $customDomain = $distInfo->custom_domain ? $distInfo->custom_domain : ''; $form->radio('domain_type') ->when(0, function (Form $form) use ($secondaryDomain) { $form->text('secondary_domain')->width(4,2)->value($secondaryDomain)->readOnly(); }) ->when(1, function (Form $form) use ($customDomain){ $form->text('custom_domain')->width(4,2)->value($customDomain)->help('Please enter the domain name, such as www.example.com,and bind the domain name to the IP address '.env('DIST_SITE_IP')); }) ->options([0=>admin_trans_field('secondary_domain'),1=>admin_trans_field('custom_domain')]) ->value($distInfo->domain_type) ->required(); }); $form->tab('site', function (Form $form) use ($distInfo) { $form->image("logo") ->autoUpload() ->uniqueName() ->accept(config('distributor.upload.oss_image.accept')) ->maxSize(config('distributor.upload.oss_image.max_size')) ->dir(config("distributor.upload.directory.image").'/logo') ->url('/dist-settings/upload') ->default($distInfo->logo); $form->text('site_name')->value($distInfo->site_name)->required(); $form->text('company_name')->value($distInfo->company_name)->required(); $form->text('company_address')->value($distInfo->company_address); $form->text('contact_number')->value($distInfo->contact_number); $form->text('service_hotline')->value($distInfo->service_hotline); $form->text('whats_app')->value($distInfo->whats_app); $form->text('seo_title')->value($distInfo->seo_title)->required(); $form->text('seo_keywords')->value($distInfo->seo_keywords); $form->textarea('seo_description')->value($distInfo->seo_description); }); return $form; } /* * 保存配置 */ public function store(Request $request) { $form = new Form(); $domainType = $request->input('domain_type'); $customDomain = $request->input('custom_domain'); if (!in_array($domainType, [0,1])) { return $form->response()->error('Invalid argument'); } if ($domainType == 1) { if (str_starts_with($customDomain,env('TOP_DOMAIN'))) { return $form->response()->error('Error in domain format'); } if (!isDomainOnly($customDomain)) { return $form->response()->error('Error in domain format'); } } DistAdminDistributor::updateDomain($domainType,$customDomain); //站点配置 DistAdminDistributor::updateInfo($request->all()); return $form->response()->success('Success'); } public function upload() { $disk = $this->disk('oss'); // 判断是否是删除文件请求 if ($this->isDeleteRequest()) { // 删除文件并响应 //return $this->deleteFileAndResponse($disk); return $this->responseDeleted(); } // 获取上传的文件 $file = $this->file(); // 获取上传的字段名称 // $column = $this->uploader()->upload_column; $column = uniqueCode("logo"); $dir = config("distributor.upload.directory.image").'/logo'; $newName = $column.'.'.$file->getClientOriginalExtension(); $result = $disk->putFileAs($dir, $file, $newName); $path = "{$dir}/$newName"; return $result ? $this->responseUploaded($path, $disk->url($path)) : $this->responseErrorMessage('文件上传失败'); } }