<?php

/* ========================================================================
 * $Id: cloud.php 1938 2020-05-19 15:15:36Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# cloud
#请求数据
if($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    $file=false;
    $_name=onez()->gp('_name');#需要的组件名称
    $_action=onez()->gp('_action');#统一传入，需解析判断
    if(strpos($_action,'?')!==false){#带参数
      $_action=substr($_action,0,strpos($_action,'?'));
    }elseif(strpos($_action,'&')!==false){#带参数，防止误写，未写?直接写&
      $_action=substr($_action,0,strpos($_action,'&'));
    }
    if(strpos($_action,':')!==false){#插件内组件或页面
      list($ptoken,$_action)=explode(':',$_action);
      if(!onez()->exists($ptoken)){
        onez()->error('插件'.$ptoken.'不存在');
      }
      $_o=explode('/',$_action);
      if($_o[0]){
        onez()->error('路径'.$_action.'写法无效');
      }
      list($_filename)=explode('.',$_o[count($_o)-1]);
      unset($_o[count($_o)-1]);
      $_o[]=$_filename;
      $_o[]=$_filename.'.php';
      $_file=implode('/',$_o);
      if(strpos($_name,'onez-page-')===0){#页面
        $file=onez($ptoken)->path.'/pages'.$_file;
        if(!file_exists($file)){
          onez()->error('插件'.$ptoken.'中不存在'.$_file.'页面');
        }
      }else{
        $file=onez($ptoken)->path.'/components'.$_file;
        if(!file_exists($file)){
          onez()->error('插件'.$ptoken.'中不存在'.$_file.'组件');
        }
      }
    }
    if($file!==false){
      $js=$css=array();
      include_once(dirname(dirname(dirname(__FILE__))).'/php/lib/build.vue.php');
      (new _vue_build(dirname($file),'component'))->vue(substr($_name,5),$js,$css);
      if($js){
        $A['js']=implode("\n",$js);
      }
      if($css[0]){
        $A['css']=implode("\n",$css);
      }
    }
  }
  return;
}
?>
<template v-if="item.ready">
  <component :is="item.is" :url-add="urlAdd" :data="item.data"></component>
</template>