Skip to content

Commit

Permalink
diy预览支持各端二维码
Browse files Browse the repository at this point in the history
  • Loading branch information
gongfuxiang committed Dec 26, 2024
1 parent c59e252 commit 0958c54
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/admin/controller/Diy.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function Detail()
*/
public function Preview()
{
MyViewAssign('data', DiyService::DiyPreviewUrl($this->data_detail));
MyViewAssign('data', DiyService::DiyPreviewData($this->data_detail));
return MyView();
}

Expand Down
24 changes: 17 additions & 7 deletions app/admin/view/default/diy/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
<!-- content start -->
<div class="content-right">
{{if $data.code eq 0}}
<iframe src="{{$data.data}}" class="mobile-iframe am-radius"></iframe>
<div class="qrcode-content am-background-white am-radius am-padding-main">
<div class="view-qrcode-init" data-value="{{$data.data}}" data-width="140" data-height="140"></div>
<div class="am-margin-top-sm am-text-center">
<span class="am-color-grey">{{:MyLang('common_service.diy.preview_scan_tips')}}</span>
<span class="text-copy-submit am-color-blue am-margin-left-sm" data-value="{{$data.data}}">{{:MyLang('common_service.diy.preview_url_copy_name')}}</span>
{{if empty($data['data']['h5_url'])}}
<div class="mobile-iframe am-padding-lg am-color-grey am-radius">{{:MyLang('common_service.diy.preview_url_tips')}}</div>
{{else /}}
<iframe src="{{$data.data.h5_url}}" class="mobile-iframe am-radius"></iframe>
{{/if}}
{{if !empty($data['data']['qrcode']) and is_array($data['data']['qrcode'])}}
<div class="qrcode-content am-background-white am-radius am-padding">
{{foreach $data.data.qrcode as $v}}
<img src="{{$v.qrcode}}" class="am-radius common-annex-view-event" width="100" data-value="{{$v.qrcode}}" data-is-download="1" data-download-name="{{$v.name}}" data-title="{{$v.name}}" data-class="am-padding-xl" />
<div class="am-margin-bottom-sm am-text-center">
<span class="am-color-grey">{{$v.name}}</span>
{{if !empty($v['url'])}}
<span class="text-copy-submit am-color-blue am-margin-left-sm" data-value="{{$v.url}}">{{:MyLang('copy_title')}}</span>
{{/if}}
</div>
{{/foreach}}
</div>
</div>
{{/if}}
{{else /}}
{{:ModuleInclude('public/not_data', ['msg'=>$data['msg']])}}
{{/if}}
Expand Down
2 changes: 0 additions & 2 deletions app/lang/cht.php
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,6 @@
'upload_config_file_handle_fail_tips' => '設定檔處理失敗',
'upload_invalid_packet_tips' => '無效數据包',
'preview_url_tips' => '請在後臺[ 手機->基礎配寘 ]先配寘手機端h5地址(h5端需要使用uniapp版本打包)',
'preview_url_copy_name' => '複製連結',
'preview_scan_tips' => '掃碼預覽效果',
'form_item_desc' => '描述',
'form_item_desc_message' => '描述內容格式2~60個字元',
'form_item_apply_version' => '適用系統版本',
Expand Down
2 changes: 0 additions & 2 deletions app/lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -1704,8 +1704,6 @@
'upload_config_file_handle_fail_tips' => 'Configuration file processing failed',
'upload_invalid_packet_tips' => 'Invalid data packet',
'preview_url_tips' => 'Please configure the H5 address on the mobile end in the background [Phone ->Basic Configuration] first (H5 end needs to be packaged using Uniapp version)',
'preview_url_copy_name' => 'Copy link',
'preview_scan_tips' => 'Scan code preview effect',
'form_item_desc' => 'describe',
'form_item_desc_message' => 'Describe content format 2-60 characters',
'form_item_apply_version' => 'Applicable system version',
Expand Down
2 changes: 0 additions & 2 deletions app/lang/spa.php
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,6 @@
'upload_config_file_handle_fail_tips' => 'Falló el procesamiento del archivo de configuración',
'upload_invalid_packet_tips' => 'Paquete de datos no válido',
'preview_url_tips' => 'Por favor, configure la dirección h5 del teléfono móvil en segundo plano [teléfono móvil - > configuración básica] primero (el lado h5 necesita ser empaquetado con la versión uniapp)',
'preview_url_copy_name' => 'Copiar enlace',
'preview_scan_tips' => 'Efecto de previsualización del Código de escaneo',
'form_item_desc' => 'Descripción',
'form_item_desc_message' => 'Formato de contenido de descripción de 2 a 60 caracteres',
'form_item_apply_version' => 'Versión del sistema aplicable',
Expand Down
2 changes: 0 additions & 2 deletions app/lang/zh.php
Original file line number Diff line number Diff line change
Expand Up @@ -1710,8 +1710,6 @@
'upload_config_file_handle_fail_tips' => '配置文件处理失败',
'upload_invalid_packet_tips' => '无效数据包',
'preview_url_tips' => '请在后台[ 手机->基础配置 ]先配置手机端h5地址(h5端需要使用uniapp版本打包)',
'preview_url_copy_name' => '复制链接',
'preview_scan_tips' => '扫码预览效果',
'form_item_desc' => '描述',
'form_item_desc_message' => '描述内容格式2~60个字符',
'form_item_apply_version' => '适用系统版本',
Expand Down
195 changes: 183 additions & 12 deletions app/service/DiyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use app\service\ResourcesService;
use app\service\AttachmentService;
use app\service\StoreService;
use app\service\AppMiniUserService;

/**
* DIY装修服务层
Expand Down Expand Up @@ -867,32 +868,202 @@ public static function DiyLegalCheck($md5_key, $data = [])
}

/**
* 预览地址
* 预览数据
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2024-09-05
* @desc description
* @param [array] $data [diy数据]
*/
public static function DiyPreviewUrl($data = [])
public static function DiyPreviewData($data = [])
{
// h5地址
$h5_url = MyC('common_app_h5_url');
if(empty($h5_url))
{
return DataReturn(MyLang('common_service.diy.preview_url_tips'), -1);
}

// 数据
if(empty($data))
{
return DataReturn(MyLang('no_data'), -1);
}

// 预览地址
$h5_url .= 'pages/diy/diy?id='.$data['id'];
return DataReturn('success', 0, $h5_url);
// h5地址
$h5_url = MyC('common_app_h5_url');

// 生成各平台二维码
$qrcode = [];
$platform = MyConst('common_platform_type');
if(!empty($platform) && is_array($platform))
{
// 自定义路径和名称
$time_dir = date('Y/m/d', is_numeric($data['add_time']) ? $data['add_time'] : strtotime($data['add_time']));
$filename = $data['id'].'.png';

// 地址信息
$page = 'pages/diy/diy';
$query = 'id='.$data['id'];
foreach($platform as $v)
{
// 存储信息
$path = 'download'.DS.'diy'.DS.'qrcode'.DS.$v['value'].DS.$time_dir.DS;
// 二维码处理参数
$dir_params = [
'path' => DS.$path,
'filename' => $filename,
'dir' => ROOT.'public'.DS.$path.$filename,
];
$status = false;
if(!file_exists($dir_params['dir']))
{
// 根据平台处理
switch($v['value'])
{
// h5
case 'h5' :
if(!empty($h5_url))
{
$ret = (new \base\Qrcode())->Create(array_merge($dir_params, ['content'=>$h5_url]));
if($ret['code'] == 0)
{
$status = true;
}
}
break;

// 微信
case 'weixin' :
$appid = AppMiniUserService::AppMiniConfig('common_app_mini_weixin_appid');
$appsecret = AppMiniUserService::AppMiniConfig('common_app_mini_weixin_appsecret');
if(!empty($appid) && !empty($appsecret))
{
$request_params = [
'page' => $page,
'scene' => $query,
'width' => 300,
];
$ret = (new \base\Wechat($appid, $appsecret))->MiniQrCodeCreate($request_params);
if($ret['code'] == 0)
{
if(\base\FileUtil::CreateDir(ROOT.'public'.DS.$path))
{
if(@file_put_contents($dir_params['dir'], $ret['data']) !== false)
{
$status = true;
}
}
}
}
break;

// 支付宝小程序
case 'alipay' :
$appid = AppMiniUserService::AppMiniConfig('common_app_mini_alipay_appid');
if(!empty($appid))
{
$request_params = [
'appid' => $appid,
'page' => $page,
'scene' => $query,
'width' => 300,
];
$ret = (new \base\Alipay())->MiniQrCodeCreate($request_params);
if($ret['code'] == 0)
{
if(\base\FileUtil::CreateDir(ROOT.'public'.DS.$path))
{
if(@file_put_contents($dir_params['dir'], RequestGet($ret['data'])) !== false)
{
$status = true;
}
}
}
}
break;

// 头条小程序
case 'toutiao' :
$config = [
'appid' => AppMiniUserService::AppMiniConfig('common_app_mini_toutiao_appid'),
'secret' => AppMiniUserService::AppMiniConfig('common_app_mini_toutiao_appsecret'),
];
if(!empty($config['appid']) && !empty($config['secret']))
{
$request_params = [
'page' => $page,
'scene' => $query,
'width' => 300,
];
$ret = (new \base\Toutiao($config))->MiniQrCodeCreate($request_params);
if($ret['code'] == 0)
{
if(\base\FileUtil::CreateDir(ROOT.'public'.DS.$path))
{
if(@file_put_contents($dir_params['dir'], $ret['data']) !== false)
{
$status = true;
}
}
}
}
break;

// 百度小程序
case 'baidu' :
$config = [
'appid' => AppMiniUserService::AppMiniConfig('common_app_mini_baidu_appid'),
'key' => AppMiniUserService::AppMiniConfig('common_app_mini_baidu_appkey'),
'secret' => AppMiniUserService::AppMiniConfig('common_app_mini_baidu_appsecret'),
];
if(!empty($config['appid']) && !empty($config['key']) && !empty($config['secret']))
{
$request_params = [
'page' => $page,
'scene' => $query,
'width' => 300,
];
$ret = (new \base\Baidu($config))->MiniQrCodeCreate($request_params);
if($ret['code'] == 0)
{
if(\base\FileUtil::CreateDir(ROOT.'public'.DS.$path))
{
if(@file_put_contents($dir_params['dir'], $ret['data']) !== false)
{
$status = true;
}
}
}
}
break;

// 快手小程序
case 'kuaishou' :
$appid = AppMiniUserService::AppMiniConfig('common_app_mini_kuaishou_appid');
if(!empty($appid))
{
$url = 'kwai://miniapp?appId='.$appid.'&KSMP_source=011012&KSMP_internal_source=011012&path='.urlencode($page.'?'.$query);
$ret = (new \base\Qrcode())->Create(array_merge($dir_params, ['content'=>$url]));
if($ret['code'] == 0)
{
$status = true;
}
}
break;
}
} else {
$status = true;
}
if($status)
{
$qrcode[] = [
'name' => $v['name'],
'type' => $v['value'],
'url' => ($v['value'] == 'h5') ? $h5_url .= $page.'?'.$query : '',
'qrcode' => ResourcesService::AttachmentPathViewHandle($dir_params['path'].$dir_params['filename']),
];
}
}
}
return DataReturn('success', 0, [
'qrcode' => $qrcode,
'h5_url' => $h5_url,
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion public/static/admin/default/css/diy.preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ body {
}
.qrcode-content {
position: absolute;
top: 20%;
top: 2rem;
left: calc(50% + 25rem);
}
.mobile-iframe,
Expand Down
8 changes: 4 additions & 4 deletions public/static/common/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3839,16 +3839,16 @@ function VoiceNotice (mp3) {
*/
function AnnexView (type, value, obj) {
if ((value || null) != null) {
var title = null;
var title = (typeof (obj) == 'object') ? (obj.attr('data-title') || null) : null;
var html = null;
var style = 'max-width:100%; max-height:calc(90vh - 4.5rem); margin: 0 auto;';
switch (type) {
case 'video':
title = window['lang_video_preview_title'] || '视频预览';
title = title || window['lang_video_preview_title'] || '视频预览';
html = '<video src="' + value + '" style="' + style + '" controls autoplay>your browser does not support the video tag</video>';
break;
default:
title = window['lang_images_preview_title'] || '图片预览';
title = title || window['lang_images_preview_title'] || '图片预览';
html = '<img src="' + value + '" class="am-block" style="' + style + '" />';
}
// 是否存在元素对象
Expand All @@ -3865,7 +3865,7 @@ function AnnexView (type, value, obj) {
config: {},
style: 'max-width: 80%; max-height: 90%; left: auto; min-width: 12rem;',
content_style: 'padding: 0; border-bottom: 0;',
content: html,
content: '<div class="'+((typeof (obj) == 'object') ? (obj.attr('data-class') || '') : '')+'">'+html+'</div>',
});
}
}
Expand Down

0 comments on commit 0958c54

Please sign in to comment.