久久精品视频18|18xxxx视频|欧美18xxxx|18xxxx中国|俄罗斯18xxxx|成人18禁|黄瓜视频18|污污污视频在线观看

幫助

【教程】會員登錄后只顯示頭像的方法

2020-11-20 20:42 易優技巧

       很久沒寫(xie)教程(cheng)了,因(yin)為最近考試的原因(yin)暫(zan)時沒有寫(xie)更多的教程(cheng),今天就來寫(xie)一個有關易優會員(yuan)登錄(lu)后頭像的問題,大家(jia)在做站(zhan)的時候,會碰(peng)到,想(xiang)登錄(lu)后只顯(xian)示頭像而不顯(xian)示賬號(hao)昵(ni)稱或者用戶(hu)名。對于(yu)目(mu)前的邏(luo)輯(ji),系統暫(zan)時還不能(neng)實現,只能(neng)應用于(yu){eyou:user type='info'}里面的 頭像加昵(ni)稱 

 才可以(yi)。 這樣會碰(peng)到(dao)瓶頸,有的模板需(xu)求(qiu)只要 單獨(du)顯示頭(tou)像就好 不要顯示昵稱

 

 

可是(shi)你怎么調用是(shi)無法實現的。

 

 

所以(yi)這種(zhong)的確 有點頭疼。小秋(qiu)今天就利用user登錄會員標簽 ;來(lai)模擬(ni)復制一(yi)個邏輯出(chu)來(lai),來(lai)填充(chong)這個所謂的不(bu)足吧,

效果如下:

 

 

如(ru)果你(ni)想(xiang)登錄顯示(shi)用戶(hu)名(ming)/昵稱  你(ni)就正常的(de)官方標簽即(ji)可。

如果你(ni)想登(deng)錄后只顯示頭像,那么就用(yong)以下標簽(qian):

 

{eyou:users type='open'}

{eyou:users type='cart'}

        <a href=&quot;{$field.url}" id="{$field.id}" >購物車(<font color="red" id="{$field.cartid}">0</font>)</a>

         {$field.hidden}

        {/eyou:users}

{eyou:users type='login'}

<a href=&quot;{$field.url}" id="{$field.id}"&gt;登錄</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='reg'}

<a href="{$field.url}&quot; id="{$field.id}">注冊</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='logout'}

<a href="{$field.url}" id="{$field.id}">退出</a> 

{$field.hidden}

{/eyou:users}

{/eyou:users}

 

代碼有點多,因為是全新復制一個標簽的結果,但我相信可以結合代碼出來,只是不想費腦,就直接全新復制標簽出來了,請多見諒~希望官方后續整合下.

 

 

以下是修改的文件部分:

打開(kai)applicationapicontroller

Ajax.php  文(wen)件(jian) 打(da)開 大概(gai)在 (179行(xing) )

 

找到以下

 

    /**

     * 檢驗會員登(deng)錄(lu)

     */

    public function check_user()

    {

        if (IS_AJAX) {

            $type = input('param.type/s', 'default');

            $img = input('param.img/s');

            $users_id = session('users_id');

            if ('login' == $type) {

      &nbsp;         if (!empty($users_id)) {

                    $currentstyle = input('param.currentstyle/s');

                    $users = M('users')->field('username,nickname,head_pic')

          &nbsp;         &nbsp;   ->where([

                            'users_id'  => $users_id,

                            'lang'      => $this->home_lang,  

                        ])-&gt;find();

&nbsp;                   if (!empty($users)) {

                        $nickname = $users['nickname'];

            &nbsp;           if (empty($nickname)) {

                            $nickname = $users['username'];

        &nbsp;               }

                        $head_pic = get_head_pic($users['head_pic']);

                        if ('on' == $img) {

                            $users['html'] = "<img class='{$currentstyle}' alt='{$nickname}' src='{$head_pic}' />";

  &nbsp;                     } else {

                            $users['html'] = $nickname;

                        }

                        $users['ey_is_login'] = 1;

                        $this->success('請求成功', null, $users);

      &nbsp;   &nbsp;         }

    &nbsp;           }

                $this->success('請(qing)先(xian)登錄', null, ['ey_is_login'=>0]);

            }

            else if ('reg' == $type)

            {

              &nbsp; if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

                } else {

                    $users['ey_is_login'] = 0;

          &nbsp;     }

                $this->success('請求成功', null, $users);

            }

            else if ('logout' == $type)

            {

                if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

              &nbsp; } else {

                    $users['ey_is_login'] = 0;

            &nbsp;   }

                $this->success('請求成(cheng)功', null, $users);

            }

            else if ('cart' == $type)

            {

                if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

                    $users['ey_cart_num_20191212'] = Db::name('shop_cart')->where(['users_id'=>$users_id])->sum('product_num');

    &nbsp;           } else {

                    $users['ey_is_login'] = 0;

                    $users['ey_cart_num_20191212'] = 0;

                }

                $this->success('請(qing)求成功', null, $users);

            }

        }

        $this->error('訪問(wen)錯誤');

    }

 

下(xia)面新增以下(xia)代碼:

 

public function check_users()

    {

        if (IS_AJAX) {

            $type = input('param.type/s', 'default');

            $img = input('param.img/s');

            $users_id = session('users_id');

            if ('login' == $type) {

                if (!empty($users_id)) {

                    $currentstyle = input('param.currentstyle/s');

                    $users = M('users')->field('username,nickname,head_pic')

        &nbsp;               ->where([

                            'users_id'  => $users_id,

                            'lang'      => $this->home_lang,  

&nbsp;                       ])->find();

$head_pic = get_head_pic($users['head_pic']);

                    if (!empty($users)) {

                        $nickname = "<img src='{$head_pic}'>";

          &nbsp;             if (empty($nickname)) {

                            $nickname = $users['username'];

                  &nbsp;     }

                        $head_pic = get_head_pic($users['head_pic']);

                        if ('on' == $img) {

                       $users['html'] = "<img class='{$currentstyle}' alt='{$nickname}' src='{$head_pic}' />";

                  &nbsp;     } else {

                            $users['html'] = $nickname;

                      &nbsp; }

                        $users['ey_is_login'] = 1;

                        $this->success('請求成功', null, $users);

                &nbsp;   }

                }

                $this->success('請(qing)先登錄', null, ['ey_is_login'=>0]);

            }

            else if ('reg' == $type)

            {

           ; &nbsp;   if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

      &nbsp;         } else {

                    $users['ey_is_login'] = 0;

              &nbsp; }

                $this->success('請(qing)求成功', null, $users);

            }

            else if ('logout' == $type)

            {

      &nbsp;         if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

    &nbsp;           } else {

                    $users['ey_is_login'] = 0;

  &nbsp;             }

                $this->success('請求(qiu)成(cheng)功', null, $users);

            }

            else if ('cart' == $type)

            {

  &nbsp;             if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

                    $users['ey_cart_num_20191212'] = Db::name('shop_cart')->where(['users_id'=>$users_id])->sum('product_num');

 ;           &nbsp;   } else {

                    $users['ey_is_login'] = 0;

                    $users['ey_cart_num_20191212'] = 0;

&nbsp;     &nbsp;         }

                $this->success('請求成功', null, $users);

            }

        }

        $this->error('訪問錯誤');

    }

保存

 

 

打開:corelibrary hink emplate aglib目(mu)錄

 

Eyou.php文件 打開

 

找(zhao)到(dao):(89行)

 

'user'       => ['attr' => 'type,id,key,mod,empty,currentstyle,img,txt,txtid'],

 

下(xia)面新增(zeng)以下(xia)代碼:

 

'users'       => ['attr' => 'type,id,key,mod,empty,currentstyle,img,txt,txtid'],

 

再(zai)找到以下代碼(大概2626行)

   public function tagUser($tag, $content)

    {

        $type  =  !empty($tag['type']) ? $tag['type'] : 'default';

        $id     = isset($tag['id']) ? $tag['id'] : 'field';

        $key     = isset($tag['key']) ? $tag['key'] : 'i';

        $txt  =  !empty($tag['txt']) ? $tag['txt'] : '';

        $txt  = $this->varOrvalue($txt);

        $txtid  =  !empty($tag['txtid']) ? $tag['txtid'] : '';

        $img  =  !empty($tag['img']) ? $tag['img'] : 'off';

        $currentstyle   = !empty($tag['currentstyle']) ? $tag['currentstyle'] : '';

 

        $parseStr = '<?php ';

        $parseStr .= ' $tagUser = new hink emplate aglibeyouTagUser;';

        $parseStr .= ' $__LIST__ = $tagUser->getUser("'.$type.'", "'.$img.'", "'.$currentstyle.'", '.$txt.', "'.$txtid.'");';

        $parseStr .= '?>';

 

        $parseStr .= '<?php if(!empty($__LIST__) || (($__LIST__ instanceof hinkCollection || $__LIST__ instanceof hinkPaginator ) && $__LIST__->isEmpty())): ?>';

        $parseStr .= '<?php $'.$id.' = $__LIST__; ?>';

        $parseStr .= $content;

        $parseStr .= '<?php endif; ?>';

        $parseStr .= '<?php $'.$id.' = []; ?>'; // 清除變量值,只限于在標簽內(nei)部使用(yong)

 

        if (!empty($parseStr)) {

    &nbsp;       return $parseStr;

        }

        return;

    }

在下面(mian)新增以下代(dai)碼:

 

   public function tagUsers($tag, $content)

    {

        $type  =  !empty($tag['type']) ? $tag['type'] : 'default';

        $id     = isset($tag['id']) ? $tag['id'] : 'field';

        $key     = isset($tag['key']) ? $tag['key'] : 'i';

        $txt  =  !empty($tag['txt']) ? $tag['txt'] : '';

  &nbsp;     $txt  = $this->varOrvalue($txt);

        $txtid  =  !empty($tag['txtid']) ? $tag['txtid'] : '';

        $img  =  !empty($tag['img']) ? $tag['img'] : 'off';

        $currentstyle   = !empty($tag['currentstyle']) ? $tag['currentstyle'] : '';

 

        $parseStr = '<?php ';

        $parseStr .= ' $tagUser = new hink emplate aglibeyouTagUsers;';

        $parseStr .= ' $__LIST__ = $tagUser->getUser("'.$type.'", "'.$img.'", "'.$currentstyle.'", '.$txt.', "'.$txtid.'");';

        $parseStr .= '?>';

 

        $parseStr .= '<?php if(!empty($__LIST__) || (($__LIST__ instanceof hinkCollection || $__LIST__ instanceof hinkPaginator ) && $__LIST__->isEmpty())): ?>';

        $parseStr .= '<?php $'.$id.' = $__LIST__; ?>';

        $parseStr .= $content;

        $parseStr .= '<?php endif; ?>';

        $parseStr .= '<?php $'.$id.' = []; ?>'; // 清(qing)除變量(liang)值(zhi),只限于在標簽內部使用

 

        if (!empty($parseStr)) {

       ;   &nbsp; return $parseStr;

        }

        return;

    }

 

再打開

corelibrary hink emplate aglibeyou 新(xin)建一個php文件 

文件名為:

TagUsers.php

 

里面內容(rong)為:以下(xia)全(quan)部復制進去:

 

<?php

/**

 * 易優cms

 * ============================================================================

 * 版權(quan)所(suo)有(you) 2016-2028 海南(nan)贊贊網絡科技有(you)限公司,并保(bao)留所(suo)有(you)權(quan)利。

 * 網站(zhan)地(di)址: //www.zhutiquan.com

  * ----------------------------------------------------------------------------

 * 如(ru)果商業用(yong)途務必到官(guan)方(fang)購(gou)買(mai)正版授權, 以免(mian)引起不必要的(de)法(fa)律糾紛.

 * ============================================================================

 * Author: 小虎(hu)哥 <1105415366@qq.com>

 * Date: 2018-4-3

 */

 

namespace think emplate aglibeyou;

 

use thinkDb;

 

/**

 * 會員中心

 */

class TagUsers extends Base

{

    /**

     * 會員ID

     */

    public $users_id = 0;

 

    //初(chu)始化(hua)

    protected function _initialize()

    {

         parent::_initialize();

        // 會員信息

        $this->users_id = session('users_id');

        $this->users_id = !empty($this->users_id) ? $this->;users_id : 0;

    }

 

    /**

     * 會員中(zhong)心

     * @author wengxianhu by 2018-4-20

     */

    public function getUser($type = 'default', $img = '', $currentstyle = '', $txt = '', $txtid = '')

    {

        $result = false;

 

        if ($this->home_lang != $this->main_lang) {

 ;           return false;

        }

 

        $web_users_switch = tpCache('web.web_users_switch');

        $users_open_register = getUsersConfigData('users.users_open_register');

 

        if ('open' == $type) {

            if (empty($web_users_switch) || 1 == $users_open_register) {

        &nbsp;      ; return false;

            }

        }

 

        if (1 == intval($web_users_switch)) {

          &nbsp; if (empty($users_open_register)) {

                $url = '';

                $t_uniqid = '';

                switch ($type) {

                    case 'login':

                    case 'centre':

                    case 'reg':

                    case 'logout':

                    case 'cart':

                        if ('cart' == $type) {

                            $shop_open = getUsersConfigData('shop.shop_open');

                            if (empty($shop_open)) return false; // 關(guan)閉商城(cheng)中心(xin),同時隱藏購(gou)物車入口(kou)

                            $url = url('user/Shop/shop_cart_list');

                        } else if ('reg' == $type) {

                            $users_open_reg = getUsersConfigData('users.users_open_reg');

  &nbsp;                         if (isset($users_open_reg) && 1 == $users_open_reg) return false;

                            $url = url('user/Users/'.$type);

&nbsp;                       } else {

                            $url = url('user/Users/'.$type);

                &nbsp;       }&nbsp;

 

        &nbsp;               $t_uniqid = md5(getTime().uniqid(mt_rand(), TRUE));

    &nbsp;                   // A標(biao)簽ID

                        $result['id'] = md5("ey_{$type}_{$this->users_id}_{$t_uniqid}");

                        // A標簽里的文(wen)案ID

                        $result['txtid'] = !empty($txtid) ? md5($txtid) : md5("ey_{$type}_txt_{$this->users_id}_{$t_uniqid}");

  &nbsp;                     // 文字文案(an)

                        $result['txt'] = $txt;

          &nbsp;             // 購物車的數量(liang)ID

                        $result['cartid'] = md5("ey_{$type}_cartid_{$this->users_id}_{$t_uniqid}");

        &nbsp;               // IMG標簽里的(de)ID

                        // $result['imgid'] = md5("ey_{$type}_img_{$this->users_id}_{$t_uniqid}");

        &nbsp;               // 圖片文案

                        $result['img'] = $img;

                        // 鏈(lian)接

                        $result['url'] = $url;

              &nbsp;         // 標簽類型(xing)

                        $result['type'] = $type;

       ;                 // 圖(tu)片樣式類

                        $result['currentstyle'] = $currentstyle;

              &nbsp;         break;

 

                    case 'info':

        &nbsp;           &nbsp;   $t_uniqid = md5(getTime().uniqid(mt_rand(), TRUE));

                    &nbsp;   $result = $this->getUserInfo();

                        foreach ($result as $key => $val) {

                            $html_key = md5($key.'-'.$t_uniqid);

&nbsp;                           $result[$key] = $html_key;

                &nbsp;       }

                        $result['t_uniqid'] = $t_uniqid;

                        $result['id'] = $t_uniqid;

                &nbsp;       break;

 

                    case 'open':

                      &nbsp; break;

 

 ;            ;       default:

  &nbsp;                     return false;

                     ; &nbsp; break;

          &nbsp;     }

 

                if ('login' == $type) {

                    if (isMobile() && isWeixin()) {

      &nbsp;                 // 微信端和小程序則(ze)使用這個(ge)url

                        $result['url'] = url('user/Users/users_select_login');

    &nbsp;               }

          &nbsp;     }

 

    &nbsp;           // 子目錄

                $result['root_dir'] = $this->root_dir;

 

                $result_json = json_encode($result);

          &nbsp;     $version = getCmsVersion();

 

                $hidden = '';

&nbsp;           &nbsp;   switch ($type) {

                    case 'login':

                    case 'reg':

                    case 'logout':

                    case 'cart':

            &nbsp;           $hidden = <<<EOF

<script type="text/javascript" src="{$this->root_dir}/public/static/common/js/tag_users.js?v={$version}"></script>

<script type="text/javascript&quot;>

    var tag_user_result_json = {$result_json};

    tag_user(tag_user_result_json);

</script>

EOF;

      &nbsp;                 break;

 

                    case 'info':

      &nbsp;                 $hidden = <<<EOF

 <script type="text/javascript" src="{$this-&gt;root_dir}/public/static/common/js/tag_users.js?v={$version}"></script>

<script type="text/javascript">

    var tag_user_result_json = {$result_json};

    tag_user_info(tag_user_result_json);

</script>

EOF;

                        break;

&nbsp;               }

                $result['hidden'] = $hidden;

            }

        }

 

        return $result;

    }

 

    /**

     * 獲取用戶信(xin)息

     */

    private function getUsersInfo()

    {

        $users = [];

        $tableFields1 = Db::name('users')->getTableFields();

        $tableFields2 = Db::name('users_level')->getTableFields();

        $tableFields = array_merge($tableFields1, $tableFields2);

        foreach ($tableFields as $key => $val) {

            $users[$val] = '';

        }

        $users['url'] = '';

        unset($users['password']);

        unset($users['paypwd']);

 

        return $users;

    }

}

 

最好再(zai)打開publicstaticcommonjs目錄

新建一個js文件(jian) 新建文件(jian)名(ming)為:tag_users.js

將以下內容全部復制進去 保存(cun):

 

function tag_user(result)

{

    var obj = document.getElementById(result.id);

     var txtObj = document.getElementById(result.txtid);

     var before_display = document.getElementById(result.id).style.display;

    var before_html = '';

    var before_txt_html = '';

    if (txtObj) {

    &nbsp;   before_txt_html = txtObj.innerHTML;

        if ('login' == result.type) {

            txtObj.innerHTML = 'Loading&hellip;';

        }

    } else if (obj) {

        before_html = obj.innerHTML;

        if ('login' == result.type) {

            obj.innerHTML = 'Loading&hellip;';

        }

    }

    if (obj) {

        obj.style.display="none";

    } else {

        obj = txtObj;

    }

    //步(bu)驟一:創建異步(bu)對(dui)象(xiang)

    var ajax = new XMLHttpRequest();

&nbsp;   //步驟二(er):設(she)置請求的(de)url參數,參數一是請求的(de)類型,參數二(er)是請求的(de)url,可以(yi)帶(dai)參數,動態的(de)傳遞參數starName到服務端

    var url = result.root_dir+"/index.php?m=api&c=Ajax&a=check_users&type="+result.type+"&img="+result.img;

    if (result.currentstyle != '') {

        url += "&currentstyle="+result.currentstyle;

    }

    ajax.open("post", url, true);

    // 給頭部(bu)添加ajax信(xin)息

    ajax.setRequestHeader("X-Requested-With","XMLHttpRequest");

    // 如果(guo)需(xu)要像 HTML 表單(dan)那樣 POST 數據(ju),請使用 setRequestHeader() 來添(tian)加 HTTP 頭。然后在(zai) send() 方法中(zhong)規定(ding)您希望發送的數據(ju):

  &nbsp; ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");

    //步驟三(san):發送請求(qiu)+數據

    ajax.send('_ajax=1');

    //步驟四:注冊事件 onreadystatechange 狀態改變就會調用(yong)

    ajax.onreadystatechange = function () {

        //步驟(zou)五 如果能夠進到這個判斷(duan) 說明 數據 完美的(de)回(hui)來(lai)了,并且請求的(de)頁面(mian)是存在的(de)

        if (ajax.readyState==4 && ajax.status==200) {

            var json = ajax.responseText;&nbsp; 

&nbsp;           var res = JSON.parse(json);

             if (1 == res.code) {

    &nbsp;           if (1 == res.data.ey_is_login) {

     &nbsp;               if (obj) {

                        if ('login' == result.type) {

                             if (result.txt.length > 0) {

                            &nbsp;   res.data.html = result.txt;

                            }

                            if (txtObj) {

  &nbsp;                             txtObj.innerHTML = res.data.html;

                     ;       } else {

                   ;             obj.innerHTML = res.data.html;

     ;                       }

                 ;           try {

&nbsp;               &nbsp;               obj.setAttribute("href", result.url);

                                if (!before_display) {

          &nbsp;                         obj.style.display=before_display;

                    &nbsp;           }

            &nbsp;       &nbsp;       }catch(err){}

                        } else if ('logout' == result.type) {

                             if (txtObj) {

               ;                 txtObj.innerHTML = before_txt_html;

     &nbsp;                       } else {

                                obj.innerHTML = before_html;

                            }

                     ;   &nbsp;   try {

&nbsp;                             &nbsp; if (!before_display) {

                                    obj.style.display=before_display;

                            &nbsp;   }

                            }catch(err){}

                        } else if ('reg' == result.type) {

                &nbsp;           obj.style.display="none";

                        } else if ('cart' == result.type) {

                &nbsp;           try {

                                var cartidObj = document.getElementById(result.cartid);

                                if (cartidObj) {

                                    cartidObj.innerHTML = res.data.ey_cart_num_20191212;

&nbsp;                               }

                       ;         if (!before_display) {

                          &nbsp;         obj.style.display=before_display;

                                }

                      &nbsp;     }catch(err){}

      &nbsp;                 }

    &nbsp;               }

        &nbsp;       } else {

 ;       &nbsp;           // 恢復(fu)未登錄前的html文案

&nbsp;         &nbsp;         if (obj) {

                      &nbsp; if (txtObj) {

                            txtObj.innerHTML = before_txt_html;

                        } else {

&nbsp;                           obj.innerHTML = before_html;

  &nbsp;             &nbsp;       }

                        if ('logout' == result.type) {

               ;             obj.style.display="none";

                        } else if ('cart' == result.type) {

    &nbsp;                       try {

        &nbsp;                       var cartidObj = document.getElementById(result.cartid);

                         ;       if (cartidObj) {

                     ;               cartidObj.innerHTML = res.data.ey_cart_num_20191212;

                      &nbsp;         }

                                if (!before_display) {

                        &nbsp;           obj.style.display=before_display;

                                }

                            }catch(err){}

     ;         &nbsp;         } else {

              &nbsp;       &nbsp;     try {

                                if (!before_display) {

                    &nbsp;               obj.style.display=before_display;

    &nbsp;                           }

                            }catch(err){}

                        }

              &nbsp;     }

               ; }

  &nbsp;         } else {

                if (obj) {

                    obj.innerHTML = 'Error';

      &nbsp;     &nbsp;       try {

                   ;     if (!before_display) {

  &nbsp;                ;         obj.style.display=before_display;

              &nbsp;         }

                  &nbsp; }catch(err){}

                }

            }

       }

    } 

}

 

function tag_user_info(result)

{

    var obj = document.getElementById(result.t_uniqid);

    var before_display = '';

    if (obj) {

&nbsp;       before_display = obj.style.display;

    &nbsp;   obj.style.display="none";

    }

 

  &nbsp; //步驟一(yi):創(chuang)建(jian)異(yi)步對象(xiang)

    var ajax = new XMLHttpRequest();

    //步驟二:設置(zhi)請求(qiu)的url參(can)(can)數(shu),參(can)(can)數(shu)一是(shi)(shi)請求(qiu)的類型,參(can)(can)數(shu)二是(shi)(shi)請求(qiu)的url,可以帶參(can)(can)數(shu),動態的傳遞參(can)(can)數(shu)starName到服務(wu)端

    ajax.open("post", result.root_dir+"/index.php?m=api&c=Ajax&a=get_tag_user_info&t_uniqid="+result.t_uniqid, true);

    // 給頭(tou)部添加ajax信息(xi)

    ajax.setRequestHeader("X-Requested-With","XMLHttpRequest";);

    // 如果需(xu)要像 HTML 表單那(nei)樣 POST 數(shu)(shu)據,請使用 setRequestHeader() 來添加 HTTP 頭。然后在 send() 方法中(zhong)規(gui)定您希望發送的數(shu)(shu)據:

    ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");

    //步驟三:發送請(qing)求(qiu)+數據

    ajax.send('_ajax=1');

&nbsp;   //步驟四:注(zhu)冊(ce)事件 onreadystatechange 狀態改變就會(hui)調用

 ;   ajax.onreadystatechange = function () {

  &nbsp;     //步驟(zou)五(wu) 如果能夠(gou)進到這個(ge)判斷 說明 數據(ju) 完美的回來(lai)了,并(bing)且請求的頁面是存在的

&nbsp;       if (ajax.readyState==4 && ajax.status==200) {

            var json = ajax.responseText;&nbsp; 

     ;       var res = JSON.parse(json);

            if (1 == res.code) {

      &nbsp;         if (1 == res.data.ey_is_login) {

    &nbsp;               var dtypes = res.data.dtypes;

    &nbsp;               var users = res.data.users;

                 ;   for (var key in users) {

                        var subobj = document.getElementById(key);

                  &nbsp; &nbsp;   if (subobj) {

                            if ('img' == dtypes[key]) {

                      &nbsp;         subobj.setAttribute("src", users[key]);

                            } else if ('href' == dtypes[key]) {

                           ;     subobj.setAttribute("href", users[key]);

      &nbsp;                     } else {

            &nbsp;            ;       subobj.innerHTML = users[key];

            &nbsp;               }

                        }

&nbsp;     &nbsp;             }

  &nbsp;                 if (obj) {

        &nbsp;       &nbsp;       try {

                   ;         if (!before_display) {

                    &nbsp;           obj.style.display=before_display;

                             }

        &nbsp;               }catch(err){}

              &nbsp;     }

               ; } else {

          &nbsp;         if (obj) {

                        obj.style.display="none";

                &nbsp;   }

          &nbsp;     }

            }

       }

    }

}

 

// 讀取 cookie

function getCookie(c_name)

{

    if (document.cookie.length>0)

    {

      c_start = document.cookie.indexOf(c_name + "=")

      if (c_start!=-1)

      { 

        c_start=c_start + c_name.length+1 

        c_end=document.cookie.indexOf(";",c_start)

        if (c_end==-1) c_end=document.cookie.length

  &nbsp;         return unescape(document.cookie.substring(c_start,c_end))

      } 

    }

    return "";

}

 

 

到這里(li)教(jiao)程就差不(bu)多(duo)了(le)。

 

為(wei)何要(yao)做2個user登錄(lu)標(biao)簽 因(yin)(yin)為(wei)有的模板只需要(yao)登錄(lu)后顯示單純頭像(xiang),一(yi)部分有的地方還是需要(yao)顯示昵稱(cheng)所(suo)以因(yin)(yin)需所(suo)調用吧。

 

重復說下  以上(shang)調用的 標(biao)簽為:

 

{eyou:users type='open'}

{eyou:users type='cart'}

        <a href="{$field.url}" id="{$field.id}" >購物(wu)車(che)(<font color="red" id="{$field.cartid}">0</font>)</a>

          {$field.hidden}

        {/eyou:users}

{eyou:users type='login'}

<a href="{$field.url}" id="{$field.id}">登錄</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='reg'}

<a href="{$field.url}" id="{$field.id}">注(zhu)冊(ce)</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='logout'}

<a href="{$field.url}" id="{$field.id}">退出</a> 

{$field.hidden}

{/eyou:users}

{/eyou:users}

 

不過一般登錄  只需

 

{eyou:users type='login'}

<a href="{$field.url}" id="{$field.id}&quot;>登錄</a> 

{$field.hidden}

{/eyou:users}

 

即可


標簽: 會員登錄

工作日 8:30-12:00 14:30-18:00
周六(liu)及部分節(jie)假日(ri)提供(gong)值班(ban)服務

易小優
轉人工 ×