小程序显示数据

1.当遍历是一条数据,取数据是个数据需要遍历,只需要取

base.y_slide进行遍历即可。

$base[‘y_slide‘] = unserialize($base[‘y_slide‘]);
$num = count($base[‘y_slide‘]);
for($i = 0; $i < $num; $i++) {
$base[‘y_slide‘][$i]=$_W[‘attachurl‘].$base[‘y_slide‘][$i];
}

2.遍历的是多条数据

foreach ($item as &$values) {
     $values[‘k_slide‘] = unserialize($values[‘k_slide‘]);
     $num = count($values[‘k_slide‘]);
    for ($i = 0; $i < $num ; $i++) {
            $values[‘k_slide‘][$i]=$_W[‘attachurl‘].$values[‘k_slide‘][$i];
}
}

3.传数据给下一个页面传id

data-k_id=‘{{item.k_id}}‘

点击事件   传id

departmentDetailClick: function(e) {

console.log(e.currentTarget.dataset.k_id)

var k_id = e.currentTarget.dataset.k_id

wx.navigateTo({

url: ‘/hyb_zylxc/department_detail/department_detail?k_id=‘ + k_id,

})

},

下一个页面  接收id

onLoad: function(options) {

var that = this;

var id = options.k_id;

that.getKeshixq(id);

// that.getIntroduction(id);

},

getKeshixq:function(id){

var that = this;

console.log(id)

app.util.request({

‘url‘: ‘entry/wxapp/Keshijianjie‘,

data: {

k_id: id

},

success: function (res) {

console.log(res.data.data)

that.setData({

keshi: res.data.data,

})

wx.setNavigationBarTitle({ title: ‘科室简介‘ });

WxParse.wxParse(‘article‘, ‘html‘, res.data.data.k_jianjie, that, 5);//百度编辑器去除非法字符显示数据

},

//百度编辑器显示数据  article

<view class="wxParse bgcf bsbb p30 fs26 c6 bgcf">

<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

</view>

4.   遍历显示数据   下拉 点击选择

<picker name="u_consultation" bindchange="zhuanjiachange" value="{{index}}" range="{{zjarrs}}">

<view wx:if="{{index == ‘‘}}" class=‘fs24 c9 ml100‘>

请选择要预约的专家

</view>

<view wx:else class="fs26 c6 ml100">

<!-- <view wx:for="{{expert}}" wx:for-item="items"> -->

<!-- {{zjarrs[index]}} -->

<input name="u_consultation" value=‘{{zjarrs[index]}}‘ disabled=‘true‘/>

<!-- </view> -->

</view>

</picker>

onLoad: function (options) {

var that = this;

that.bindPickerChange();

},

bindPickerChange: function () {

var that =this;

app.util.request({

‘url‘: "entry/wxapp/YuZhuanjia",

success:function(e){

var arrs = e.data.data;

var zjarrs = [];

for (var i = 0; i < arrs.length;i++){

zjarrs.push(arrs[i].z_name);

}

that.setData({

expert: e.data.data,

zjarrs: zjarrs

})

}

})

},

zhuanjiachange:function(e){

console.log(‘picker发送选择改变,携带值为‘, e.detail.value)

console.log(this.data.expert);//预约专家

this.setData({

index:e.detail.value

})

},

5.地图

<view data-longitude="{{longitude}}" data-latitude="{{latitude}}" class=‘bdl2 df fdc w50 aic jcc bdbb pt30 pb30‘ bindtap=‘Position‘>

//来院路线

choosePosition: function() {

var that = this;

app.util.request({

‘url‘: ‘entry/wxapp/Base‘,

success: function (res) {

console.log(res.data.data);

that.setData({

base: res.data.data,

latitude:res.data.data.latitude,

longitude:res.data.data.longitude

})

},

fail: function (err) {

console.log(err)

},

});

},

Position:function(e){

var latitude = e.currentTarget.dataset.latitude

var longitude = e.currentTarget.dataset.longitude

console.log(latitude, longitude);

wx.openLocation({

latitude: parseFloat(latitude),

longitude: parseFloat(longitude),

scale: 28

})

},

6.点击切换

<scroll-view class=‘bsbb pl30 bgcf bdb2‘ scroll-x style=‘white-space:nowrap;‘>

<block wx:for="{{caseArr}}" wx:key="unique">

<text data-index="{{index}}" class=‘fs24 dib bsbb h80 mr50 {{current == index?"c bdb4":"c9"}}‘ bindtap=‘huoqu‘>{{item.j_name}}</text>

</block>

</scroll-view>

<!-- <my-sku-page data-index="{{pIndex[index]}}" wx:key="unique" binddetailBtn="checkClick" style="display:{{current == pIndex[index]?‘block‘:‘none‘}}" >

</my-sku-page> -->

<!-- <view wx:for="{{caseArr}}" wx:for-item="items"> -->

<scroll-view class="bsbb pl30 df pt30 pb30 bgcf h310" scroll-x style=‘white-space:nowrap;‘>

<block wx:for="{{caseArr[current].binzhen}}" wx:key="unique">

<view data-j_id="{{item.j_id}}" class=‘dib tac mr15‘ bindtap="checkClick">

<view>

<image mode=‘aspectFill‘ style=‘width:178rpx;height:178rpx;‘ src=‘{{item.j_thumb}}‘ class=‘db‘></image>

</view>

<text class=‘db fs26 c9 mt20‘>{{item.j_name}}</text>

</view>

</block>

</scroll-view>

current: 0,

huoqu: function(e) {

var that = this

console.log(e)

var index = e.currentTarget.dataset.index

var current = index;

that.setData({

current: current

})

7.分享转发

onShareAppMessage: function() {

//分享

// console.log("分享")

var that = this

// console.log("分享1")

return {

title: ‘双十一来了瞧一瞧看一看喽‘,

path: ‘/hyb_zylxc/index/index‘,

success: res => {

// console.log("分享2")

// console.log("分享成功" + res)

console.log(res.shareTickets[0]);

// shareTicket 是获取转发目标群信息的票据,只有拥有 shareTicket 才能拿到群信息,用户每次转发都会生成对应唯一的shareTicket 。

// 如果这里有 shareTickets,则说明是分享到群de 如果没有则是转发到好友的

wx.getShareInfo({

shareTicket: res.shareTickets[0],

success: res => {

that.setData({

isShow: true

})

console.log(that.setData.isShow)

},

fail: function (res) { console.log(res) },

complete: function (res) { console.log(res) }

})

},

fail: function (res) {

console.log("分享失败" + res)

}

}

}

8.检索事件选择,选择男装的上衣

<picker bindchange="bindDepartmentChange" value="{{index}}" range="{{introduction}}" class="w33">

<view wx:if="{{index == ‘‘}}" class=‘df jcc aic fs28 c9‘>

<text>全部科室</text>

<image mode=‘widthFix‘ style=‘width:27rpx‘ src=‘../images/down.png‘ class=‘ml15‘></image>

</view>

<view wx:else class=‘df jcc aic fs28 c9 ‘>

<text>{{introduction[index]}}</text>

<!-- <input name="u_consultation" value=‘{{introduction[index]}}‘ disabled=‘true‘ /> -->

<image mode=‘widthFix‘ style=‘width:27rpx‘ src=‘../images/down.png‘ class=‘ml15‘></image>

</view>

</picker>

下标:data :{

index: "",

}

that.getYuZhuanjiajiansuo(‘‘, ‘‘, ‘‘);//专家检索

选择显示

bindPickerChange: function () {

var that = this;

app.util.request({

‘url‘: "entry/wxapp/Keshi",

success: function (e) {

console.log(e.data.data);

var arrs = e.data.data;

var introduction = [];

for (var i = 0; i < arrs.length; i++) {

introduction.push(arrs[i].k_name);

}

that.setData({

keshi: e.data.data,

introduction: introduction

})

}

})

},

//科室

bindDepartmentChange: function (e) {

var that = this;

that.setData({

index: e.detail.value//下标

})

var keshi = that.data.introduction[e.detail.value];

var zhicheng = that.data.zhicheng[that.data.appellation];

var shanchang = that.data.specialityArr[that.data.speciality]

if(zhicheng==undefined){

var zhicheng = ‘‘;

}

if (shanchang==undefined){

var shanchang = "";

}

that.getYuZhuanjiajiansuo(keshi, zhicheng, shanchang);

},

getYuZhuanjiajiansuo:function(keshi,zhicheng,shanchang){

var that = this;

app.util.request({

‘url‘: ‘entry/wxapp/YuZhuanjiajiansuo‘,

‘data‘:{

keshi: keshi,

zhicheng:zhicheng,

shanchang: shanchang

},

success: function (res) {

console.log(res.data.data);

that.setData({

expert: res.data.data,

})

},

fail: function (err) {

console.log(err)

},

});

},

//专家检索
public function doPageYuZhuanjiajiansuo(){
global $_W,$_GPC;
$uniacid = $_W[‘uniacid‘];
$keshi = $_REQUEST[‘keshi‘];
$zhicheng = $_REQUEST[‘zhicheng‘];
$shanchang = $_REQUEST[‘shanchang‘];
$where = " where uniacid=:uniacid";
if (!empty($keshi)) {
$where.=" and keshi=:keshi";
$data[":keshi"] = $keshi;
}
if (!empty($zhicheng)) {
$where.=" and z_zhicheng=:zhicheng";
$data[":zhicheng"] = $zhicheng;
}
if (!empty($shanchang)) {
$where.=" and z_shanchang like ‘%$shanchang%‘";    //很多不止一个,
}
$data[‘:uniacid‘] = $uniacid;
$sql = "SELECT * FROM ".tablename("hyb_ylxc_zhuanjia").$where;
// $sql = "SELECT * FROM ".tablename("hyb_ylxc_zhuanjia")."where uniacid=:uniacid",array(":uniacid"=>$uniacid);
$list = pdo_fetchall($sql,$data);
if (!empty($list)) {
foreach ($list as &$value) {
$value[‘z_thumbs‘] = $_W[‘attachurl‘].$value[‘z_thumbs‘];
$base = pdo_fetch("SELECT * FROM ".tablename("hyb_ylxc_base")." where uniacid=:uniacid",array(":uniacid"=>$uniacid));
$value[‘yiyuan‘] = $base[‘y_title‘];

}

}
return $this->result(0,"success",$list);
}

9.用户授权

//获取用户信息
public function doPageTyMember() {
global $_GPC, $_W;
$uniacid = $_W[‘uniacid‘];
$openid = $_REQUEST[‘openid‘];
// $openid = "oiw7_0FlOxmb4SmYHwT7K0rBdCnY";
$item[‘u_name‘] = $_GPC[‘u_name‘];
$item[‘u_thumb‘] = $_GPC[‘u_thumb‘];
$item[‘uniacid‘] = $uniacid;
if ($openid) {
$res = pdo_update(‘hyb_ylxc_userinfo‘, $item, array(‘openid‘ => $openid));
}
if (!$res[‘u_id‘]) {
$res = pdo_fetch(‘SELECT `u_id` FROM ‘ . tablename(‘hyb_ylxc_userinfo‘) . " where `openid`=‘{$openid}‘");
}
$message = ‘success‘;
$errno = 0;
return $this->result($errno, $message, $item);
}
public function doPageGetUid() {

global $_GPC, $_W;
$uniacid = $_W[‘uniacid‘];
$result = pdo_fetch(‘SELECT * FROM ‘ . tablename(‘hyb_ylxc_key‘) . " where `uniacid`=‘{$uniacid}‘");
// $APPID = "wxbcf230862644aa93";
$APPID = $result[‘appid‘];
$SECRET = $result[‘appsecret‘];
// $SECRET = "1ad4414c9da569ca333d216cc6d0f643";
$openid = $_REQUEST[‘openid‘];
$openid = "oiw7_0FlOxmb4SmYHwT7K0rBdCnY";
$code = trim($_GPC[‘code‘]);
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$APPID}&secret={$SECRET}&js_code={$code}&grant_type=authorization_code";
$data[‘userinfo‘] = json_decode($this->httpGet($url));
$openid = $data[‘userinfo‘]->openid;
$item[‘openid‘] = $openid;
if ($openid) {
$res = pdo_fetch(‘SELECT `u_id` FROM ‘ . tablename(‘hyb_ylxc_userinfo‘) . " where `openid`=‘{$openid}‘");
if (!$res[‘u_id‘]) {
$res = pdo_insert(‘hyb_ylxc_userinfo‘, $item);
}
}
$data[‘openid‘] = $openid;
$message = ‘success‘;
$errno = 0;
return $this->result($errno, $message, $data);
}

bindGetUserInfo: function(e) {

var that = this;

console.log(e);

console.log(e.detail.userInfo)

wx.login({

success: res => {

// ------ 获取凭证 ------

var code = res.code;

console.log(code);

if (code) {

// console.log(‘获取用户登录凭证:‘ + code);

// ------ 发送凭证 ------

app.util.request({

"url": "entry/wxapp/GetUid",

data: {

code: code

},

method: ‘POST‘,

header: {

‘content-type‘: ‘application/json‘

},

success: function(res) {

console.log(res);

var openid = res.data;

if (res.statusCode == 200) {

// console.log("获取到的openid为:" + res.data)

// that.globalData.openid = res.data

wx.setStorageSync(‘openid‘, res.data),

wx.setStorage({

key: ‘userinfo‘,

data: true,

}),

that.setData({

userinfo: true

})

//设置用户信息

wx.getUserInfo({

success: res => {

console.log(res);

var u_name = e.detail.userInfo.nickName;

var u_thumb = e.detail.userInfo.avatarUrl;

console.log(u_name);

console.log("aa" + res)

console.log("aa"+res.errMsg)

wx.setStorageSync("avatar", res.userInfo.avatarUrl)

if (res.userInfo.nickName != wx.getStorageSync("nickName")) {

app.util.request({

"url": ‘entry/wxapp/TyMember‘,

data :{

u_name:u_name,

u_thumb:u_thumb,

},

method: ‘POST‘,

header: {

‘content-type‘: ‘application/json‘

},

success: function (res) {

console.log(res);

if (res.statusCode == 200) {

// console.log("获取到的openid为:" + res.data)

// that.globalData.openid = res.data

wx.setStorageSync(‘u_name‘, res.data)

wx.getStorageSync(‘u_thumb‘, res.data)

} else {

console.log(res.errMsg)

}

},

})

}

}

})

} else {

console.log(res.errMsg)

}

}

})

}

},

fail: function (err) {

console.info(err.errMsg);

wx: showModal({

title: ‘警告‘,

cancelText: ‘不授权‘,

confirmText: ‘授权‘,

confirmColor: ‘#37c31a‘,

content: ‘若不授权微信登录,则无法使用XXXXXX;点击重新获取授权,则可重新使用;‘ +

‘若点击不授权,将无法使用便捷服务。‘,

success: function (res) {

if (res.confirm) {

console.log(‘用户点击确认‘);

wx.openSetting({

success: res => {

if (res.authSetting[‘scope.userInfo‘]) {

wx.getUserInfo({

success: res => {

console.log(‘用户同意授权‘ + res.userInfo.nickName)

app.util.request({

‘url‘: ‘entry/wxapp/TyMember‘,

data: {

u_name: u_name,

u_thumb: u_thumb

},

method: ‘POST‘,

header: {

‘content-type‘: ‘application/json‘

},

success: function (res) {

console.log(res);

if (res.statusCode == 200) {

// console.log("获取到的openid为:" + res.data)

// that.globalData.openid = res.data

wx.setStorageSync(‘openid‘, res.data)

} else {

console.log(res.errMsg)

}

},

})

}

})

} else {

console.info(‘再次不允许‘);

}

}

})

} else if (res.cancel) {

console.log(‘弹出框用户点击取消‘)

}

}

})

}

})

},

private function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}

10   查询男女  数据库是1  0,页面显示男女

$sex = $data["h_sex"];
if($sex==1){
$data[‘h_sex‘] = "女";

}
else{
$data[‘h_sex‘] = "男";
}

11.

原文地址:https://www.cnblogs.com/isuansuan/p/9861390.html

时间: 2024-12-13 18:42:32

小程序显示数据的相关文章

小程序--data 数据各种形式和运算

微信小程序的数据的运算和显示和ng原理差不多,主要分为以下几种方式: 1: 字符串 2: 数字的直接加减 3:json对象 注意里面的对象名称不能出现'-'不然在页面无法渲染 4:字符串拼接(包括数字) 5:直接定义id和class的名称等属性值 例子如下: wxjs: data: { //定义的变量名字不能有--出现,不然无法显示 如group-name获取的对象里面的定义名字也不能出现 logs:'直接绑定数据字符',//直接绑定数据字符 classname:'bind-class',idn

微信小程序开放数据解密 AES-128-CBC 解密(C#版本)

最近在开发小程序,需要跟微信服务端交互,微信敏感数据都有加密返回,需要在服务端接收进行解密后再返回给客户端小程序,今天就通过C# 进行数据的解密,官方下载下来是Node.C++.php等,就是没有C# 代码,于是就上度娘,找到 https://blog.csdn.net/jasonsong2008/article/details/83586119 https://www.cnblogs.com/jetz/p/6384809.html 经过一番研究,搞定啦,其实就是用了aes加密方法. 下面把第一

[转]微信小程序登录数据解密以及状态维持

本文转自:http://www.cnblogs.com/cheesebar/p/6689326.html 学习过小程序的朋友应该知道,在小程序中是不支持cookie的,借助小程序中的缓存我们也可以存储一些信息,但是对于一些比较重要的信息,我们需要通过登录状态维持来保存,同时,为了安全起见,用户的敏感信息,也是需要加密在网络上传输的. 前台,service.封装了http请求,同时封装了getSession(通过code获取服务器生成的session).getUserInfo(获取用户信息).ge

微信小程序 --- 缓存数据

保存数据  /  读取数据  /  删除数据  /  数据异步操作 每一个微信小程序都可以有自己的本地缓存,可以通过wx.setStorage( wx.setStorageSync) ,wx.getStorage(wx.getStorageSync),wx.clearStorage(wx.clearStorageSync) 可以对本地缓存进行设置 / 获取和清理.本地缓存最大为 10MB ; ...Sync 是同步的接口:不带这个的是一个异步的接口: 注意:localStorage 是永久存储的

小程序echarts数据不改变,或者是一次渲染成功,第二次进入,渲染失败的解决办法

1.引入echarts插件: import * as echarts from '../../ec-canvas/echarts'; 2.data中定义: ecBar: { onInit: initChart }, 3.app.js中定义全局变量: globalData: { userInfo: null, all_date: [] }, 4.onload中,定义一个  all_date ,用来接收数据 5.循环出来的数据,赋值:app.globalData.all_date = all_dat

小程序 显示对话框 确定-取消

详细参数见小程序API:https://developers.weixin.qq.com/miniprogram/dev/api/wx.showModal.html wx.showModal({ title: '确定关闭吗', content: '还没有保存确定关闭吗', success(res) { if (res.confirm) { console.log('用户点确定了') } else if (res.cancel) { console.log('用户点击取消') } } 总结: 类似

微信小程序 修改数据,并动态渲染页面;修改数组;

一.修改数据,并在页面动态渲染 this.setData({ txt: '12112' }) 二.修改数组 var rotateClassItem = 'rotateClass['+ index + ']'; that.setData({ [rotateClassItem]: !that.data.rotateClass[index] }) 原文地址:https://www.cnblogs.com/siyecao2010/p/10083896.html

微信小程序绑定数据

视图文件里使用{{}}可以绑定数据,: <image src="{{like?'images/like_on.png':'images/like.png'}}"></image> 再到组件js里定义data数据即可实现数据的绑定 data: { like:true }, 使用组件的时候要遵循封装性,开放性等原则 使用变量保存这两张图片的路径: data: { like:true, yesSrc: 'images/like_on.png', noSrc: 'ima

微信小程序实现数据监听

/** * 设置监听器watch.js */ export function setWatcher(page) { let data = page.data; let watch = page.watch; Object.keys(watch).forEach(v => { let key = v.split('.'); // 将watch中的属性以'.'切分成数组 let nowData = data; // 将data赋值给nowData for (let i = 0; i < key.l