需要前后端配合;后端thinkphp 

uniapp 配置;

 服务端解压

thinkphp 代码

控制器代码

<?php

namespace app\h5\controller;

use app\data\model\DataUserMessage;
use think\admin\Controller;

class Index extends Controller
{

    private $tar_getversion = 'h5v20230806';

    public function index()
    {
        $path = $this->app->getRootPath() . '/public/';
        //获取public 所有包含 h5 的目录
        $data = scandir($path);
        $list = [];
        $index_str = 'h5v';
        foreach ($data as $item) {
            if(is_dir($path.$item)){
                if (strpos($item, $index_str) !== false) {
                    $item2 = str_replace($index_str, "", $item);
                    $list[] = $item2 ?? '0';
                }
            }
        }
        rsort($list);
        $version = $index_str . $list[0];
        if (!empty($this->tar_getversion)) {
            $version = $this->tar_getversion;
        }
        $this->assign([
            'version' => '/' . $version
        ]);
        $this->fetch('');
    }



}

视图代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
<script>
    var ver = "{$version}";
    var full_url = location.href;
    console.log(full_url)
    var res_url = full_url.replace("/h5", ver)
    console.log(res_url)
    window.location.href=res_url;
</script>
</body>
</html>

访问页面

127.0.0.1:8000/h5

会自动调转到最新的安装包

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐