vue 判断是否位 float_微擎独立后台TP5+VUE分离+小程序

微擎2.0已经不允许从应用入口直接跳独立后台,需要从应用菜单中进入独立后台。
如菜单标识入口设置为cms,就是对应的site.php中doWebCms方法
在该方法中,把小程序,公众号等key和secret等放到session中,然后跳转到tp5的入口文件即可。
有点需要注意,TP5的session前缀默认是think,所有直接seesion::get()是获取不到微擎session的

*****微擎******
//doWeb为后台方法
public function doWebCms() {
    global $_W,$_GPC;    
        
        $this->checkModuleFile();// 验证模块核心文件        
        $this->session();// 设置session登录状态       
        $this->jump_cms(); // 跳转到独立后台
}

private function checkModuleFile()
    {
        $module_file = __DIR__ . '/api/thinkphp/index.php';
        !file_exists($module_file) && itoast('模块文件不存在', referer(), 'error');

        if (session_status() != PHP_SESSION_ACTIVE){
              itoast('未开启session', referer(), 'error');
        }
    }

//单管理模式,自动登录。如果有管理员权限控制,那还是手动登录较好
private function session()
    {
        @session_start();
        $_SESSION['qy2019'] = [
            'wxapp' => [
                'wxapp_id' => $this->wechat_app['uniacid']
            ],
            'we7_data' => [
                'wxapp_id' => $this->wechat_app['uniacid'],
                'app_name' => $this->wechat_app['name'],
                'app_id' => $this->wechat_app['key'],
                'app_secret' => $this->wechat_app['secret'],
            ],
            'is_login' => true
        ];
    }

private function jump_cms()
    {
        global $_W;
        $url = "{$_W['siteroot']}addons/{$_W['current_module']['name']}/cms/index.html";
        header('Location:' . $url);  //header跳转不好用,session,缓存等都无法传递。改用js跳转
        exit;
    }
******TP5****** 
public function login(){  
      session_start();  
      dump($_SESSION['qy2019']);
      return $this->fetch();
    }

TP5数据库配置文件自动获取微擎配置

defined('IN_IA') or define('IN_IA', true); 这句必须要有,不然会报错

defined('IN_IA') or define('IN_IA', true);
require __DIR__ . '/../../../../data/config.php';

$db=[];
if (empty($config['db']['master'])){
    $db=$config['db'];
}else{
    $db=$config['db']['master'];
}
return [
    // 数据库类型
    'type'            => 'mysql',
    // 服务器地址
    'hostname'        => $db['host'],
    // 数据库名
    'database'        => $db['database'],
    // 用户名
    'username'        => $db['username'],
    // 密码
    'password'        => $db['password'],
    // 端口
    'hostport'        => $db['port'],

VUE打包后的生产版如何在微擎中使用

1、vue默认打包是根目录位置,要放在其他目录使用必须新建配置vue.config.js文件,配置baseUrl: "/cms/"。
      放入tp5默认入口public目录下 ,即public/cms
2、页面跳转用 this.$router.push({path: '/login', query:{id:id}}); 方式。
3、axios请求用相对路径 Api_url='../'   //相对路径指向public/index.php

那么当访问微擎的doWebCms()方法,就自动跳转到了vue的index.html页面

微擎底部版权--商业版不显示,非商业版显示


判断方法是site.php中查看$_W['setting']['copyright']['footerright']是否存在,商业版有信息,非商业版为空。

//api端:site.php
  public function doMobileCpy() {
        global $_W; 
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: token,Origin, X-Requested-With,X_Requested_With, Content-Type, Accept");
        header('Access-Control-Allow-Methods: POST,GET,PUT'); 
        $arr=$_W['setting']['copyright']['footerright'];
        $json=json_encode($arr);
        echo $json;
    }
//vue端:app.vue
 <div class="friend-link" v-if="!cpy">        
        <a href="http://www.w7.cc">微信开发</a>&emsp;
        <a href="http://s.w7.cc">微信应用</a>&emsp;
        <a href="http://bbs.w7.cc">微擎论坛</a>&emsp;
        <a href="http://s.w7.cc">联系客服</a>
      </div>
      <div class="friend-link" v-else>        
        {{cpy}}
      </div>

 mounted() {  
    const that=this  
    const host=window.location.host
    const protocol=window.location.protocol
    axios.get(protocol+'//'+host+"/app/index.php?i=2&c=entry&do=Cpy&m=xxxx")
        .then(function(res){ 
          that.cpy=res.data
      }); 
  }

独立小程序转微擎版


小程序既然是独立的,就不需要使用微擎的小程序文件包了。
既然是独立的肯定也不能访问微擎的wxapp.php,而是访问独立的api,路径就是:http://www.xxx.com/addons/应用模块名称/tp5/index.php
其实只需要加入一个微擎的siteinfo文件,app.js引入该文件的域名http://www.xxx.com和uniacid做使用,访问API即可。

注意支付回调时,不同unicid的问题


另一篇文章有介绍


参考:http://www.ruhuashop.com

01f9ec473590397d2b611baef47f66f3.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值