You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.5 KiB
118 lines
3.5 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\Request;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 静态资源访问接口
|
|
* Class StaticResource
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class StaticResource extends BaseApiService
|
|
{
|
|
|
|
/**
|
|
* 获取静态资源URL
|
|
*/
|
|
public function getResourceUrl(Request $request)
|
|
{
|
|
$resource_path = $request->param('path', ''); // 资源路径,如:icon-img/home.png
|
|
|
|
if (empty($resource_path)) {
|
|
return fail('资源路径不能为空');
|
|
}
|
|
|
|
// 基础URL配置 - 从配置文件或环境变量读取
|
|
$baseUrl = $request->domain() ?: 'http://localhost:20080';
|
|
|
|
// 构建完整的静态资源URL
|
|
$resourceUrl = $baseUrl . '/static/resource/uniapp/' . $resource_path;
|
|
|
|
return success([
|
|
'resource_url' => $resourceUrl,
|
|
'base_url' => $baseUrl . '/static/resource/uniapp/',
|
|
'path' => $resource_path
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 批量获取静态资源URL
|
|
*/
|
|
public function getBatchResourceUrls(Request $request)
|
|
{
|
|
$paths = $request->param('paths', []); // 资源路径数组
|
|
|
|
if (empty($paths) || !is_array($paths)) {
|
|
return fail('资源路径数组不能为空');
|
|
}
|
|
|
|
// 基础URL配置
|
|
$baseUrl = $request->domain() ?: 'http://localhost:20080';
|
|
$baseResourceUrl = $baseUrl . '/static/resource/uniapp/';
|
|
|
|
$results = [];
|
|
foreach ($paths as $path) {
|
|
$results[$path] = $baseResourceUrl . $path;
|
|
}
|
|
|
|
return success([
|
|
'base_url' => $baseResourceUrl,
|
|
'resources' => $results
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 获取所有可用的图标资源
|
|
*/
|
|
public function getIconList(Request $request)
|
|
{
|
|
$baseUrl = $request->domain() ?: 'http://localhost:20080';
|
|
$baseResourceUrl = $baseUrl . '/static/resource/uniapp/';
|
|
|
|
// 定义所有可用的图标
|
|
$icons = [
|
|
'delete.png',
|
|
'ding_wei.png',
|
|
'empty.png',
|
|
'guoqi.png',
|
|
'home-active.png',
|
|
'home.png',
|
|
'kkry.png',
|
|
'liu.png',
|
|
'loading_white.png',
|
|
'notice.png',
|
|
'profile-active.png',
|
|
'profile.png',
|
|
'tou.png',
|
|
'uploadImg.png',
|
|
'used.png',
|
|
'warn.png',
|
|
'weixin.png'
|
|
];
|
|
|
|
$iconUrls = [];
|
|
foreach ($icons as $icon) {
|
|
$iconUrls['icon-img/' . $icon] = $baseResourceUrl . 'icon-img/' . $icon;
|
|
}
|
|
|
|
// 添加评分图标
|
|
$iconUrls['rate/none.png'] = $baseResourceUrl . 'rate/none.png';
|
|
|
|
return success([
|
|
'base_url' => $baseResourceUrl,
|
|
'icons' => $iconUrls,
|
|
'count' => count($iconUrls)
|
|
]);
|
|
}
|
|
}
|