没事多喝水

技术笔记&记录生活点滴

  • 首页
  • 读书
  • 观影
  • 笔记
  • 读书笔记
  • Android学习
  • 生活
  • 吹口琴
  • 爱咖啡
  • IT技术-文档
  • 日常桌面
  • 数据库
  • CI/CD运维
  • Android开发
  • 小程序&微网页
  • Web开发
  • 产品
  • 教学
  • 安卓
  • 关于
  • 标签
  • 搜索

微信小程序-常用自定义函数

发表于 2019-09-25 | 更新于 2020-03-02 | 分类于 技术

ajax

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const ajaxPromisify = function(options={}) {
return new Promise((resolve,reject) => {
wx.showLoading({title: '加载中'});
wx.request({
url: options.url,
method: options.method,
data: options.data,
success:function(res){
wx.hideLoading();
resolve(res);
},
fail:function(res){
reject(res);
}
});
});
};

用户认证信息获取,没有获取到就弹框

1
2
3
4
5
6
7
8
9
10
11
12
13
const userPromisify = function() {
return new Promise((resolve,reject) => {
wx.getUserInfo({
success:function(res){
resolve(res);
},
withCredentials:true,
fail:function(res){
reject(res);
}
});
});
};

微信登陆

1
2
3
4
5
6
7
8
9
10
11
12
13
const wxLogin = function() {
return new Promise((resolve,reject) => {
wx.login({
success:function(res){
resolve(res);
},
withCredentials:true,
fail:function(res){
reject(res);
}
});
});
}

判断某些权限是否获取到

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const authSettingPromisify = function(authtype) {
return new Promise((resolve,reject) => {
wx.getSetting({
success(res) {
if (!res.authSetting[authtype]) {
resolve(false);
}else {
resolve(true);
}
},
fail(err) {
reject(err);
}
});
});
};

微信小程序-跳转-本地获取存储-手机号验证

发表于 2019-09-24 | 更新于 2020-03-02 | 分类于 技术

获取本地存储

1
2
3
4
5
//获取本地存储
wx.getStorageSync("SysInfo").permission.title;

//设置本地存储
wx.setStorageSync("UserID", data.data.user_id);

跳转

1
2
3
4
5
//直接跳转并不删除当前页面
wx.navigateTo({'url':'/pages/shop/c/register/register'});

//删除当前页面并跳转
wx.redirectTo({'url':'/pages/shop/c/register/register'});

手机号验证

1
2
3
4
const phoneVerification = function(phone) {
let reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
return reg.test(phone);
}

微信小程序-弹框插件

发表于 2019-09-24 | 分类于 前端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 下载
git clone git@github.com:konggeyuan/popup.git

//json文件定义
"usingComponents": {
"zx-popup": "/components/zx-popup/index"
}

//页面
<button bindtap="bottomPop">显示bottom弹框</button>

//弹框界面
<zx-popup popup-visible="{{ bottom }}" zx-position="{{'bottom'}}" bind:popupStatus="popupChange">
<view class="wrap bottom">显示bottom弹框</view>
</zx-popup>

//调用
bottomPop() {
this.setData({
bottom: true
});
},

//状态events
popupChange() {
console.log(this.data.bottom);
},

微信小程序-环境标题设置

发表于 2019-09-24 | 分类于 前端
1
2
3
4
5
6
7
8
9
10
11
//首页标题
data = {"type":"title","position":{"type":"wx-title","value":"user"}};
wx.request({
method:'POST',
url: utils.restfulUrl+"layout",
data: JSON.stringify(data),
success: ({ data }) => {
that.setData({ title: data.data[0].title || [] });
wx.setNavigationBarTitle({title: data.data[0].title});
}
});
1
2
3
4
5
6
7
8
9
10
11
console.log('列表导航');
data = {"type":"title","position":{"type":"wx-nav-user"}};
wx.request({
method:'POST',
url: utils.restfulUrl+"layout",
data: JSON.stringify(data),
success: ({ data }) => {
// console.log(data.data);
that.setData({ subObj: data.data || [] });
}
});
1
2
3
4
5
6
7
8
9
10
11
//首页标题
data = {"type":"title","position":{"type":"wx-title","value":"user"}};
wx.request({
method:'POST',
url: utils.restfulUrl+"layout",
data: JSON.stringify(data),
success: ({ data }) => {
that.setData({ title: data.data[0].title || [] });
wx.setNavigationBarTitle({title: data.data[0].title});
}
});
1
2
3
 // 用户是否登陆
let userObj = wx.getStorageSync("user_info") || false;
that.setData({userObj:userObj});
1
2
3
4
5
6
7
8
appInstance.loginStat();
console.log('登陆状态');

appInstance.sysInfo();
console.log('系统环境信息');

appInstance.tabBar();
console.log('底部导航');

layui常用部件

发表于 2019-09-12 | 更新于 2019-09-17 | 分类于 前端

静态表格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<table lay-size="sm" class="layui-table">
<!-- 定义单元格高宽 -->
<colgroup>
<col width="10">
<col width="300">
<col>
</colgroup>
<!-- 定义第一行高宽 -->
<thead>
<tr>
<th></th>
<th>{$lang.card_sn}</th>
<th>{$lang.user_phone}</th>
</tr>
</thead>
<tbody>
<!-- {foreach from=$cards item=card} -->
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>

form表单

1
2
3
4
5
6
7
8
9
10
11
12
13
<!--文本框-->
<input type="text" name="points" value="" placeholder="" autocomplete="off" class="layui-input" />

<!--文本域-->
<textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>

<!--加按钮标记的图标-->
<button id="card_edit" type="button" class="layui-btn layui-btn-sm layui-bg-cyan" title="{$lang.edit}">
<i class="layui-icon">&#xe642;</i>
</button>

layui-btn-normal 普通蓝色按钮
layui-btn-danger 红色警告按钮

laravel 数据库结构化查询

发表于 2019-09-11 | 更新于 2020-03-05 | 分类于 技术

插入数据库

1
Companyauth::insert($data);

更新

1
Companyauth::where('uid',$uid)->update($data);

查询

1
Companyauth::where('uid',$uid)->find(1);

orderBy和limit组合

1
Companyauth::orderBy('id','desc')->take(6)->get();

where条件

1
2
Newsinformation::where('id','<',$id)->first();
Orderbook::where('buyId',$uid)->get();

left join

1
2
3
$prdList = Product::where('product.type',2)
->leftjoin('companyauth','companyauth.uid','=','product.uid')
->orderBy('product.id','desc')->get();

从配置文件读取数据

1
$choiseType = Config::get('user.choicetype');

单一纪录

1
Newsinformation::where('id','<',$id)->first();

连表查询、排序

1
2
3
4
5
6
7
8
9
10
11
12
$fields = [
'op.id','op.product_id','op.product_number as num',
'pd.image','op.name','op.order_id'
];

DB::table('order_product as op')
->select($fields)
->leftJoin('product as pd', 'pd.id', '=', 'op.product_id')
->where('op.order_id',$orderId)
->orderBy('id','desc')
->limit(6)
->get();

单一查询

1
2
3
4

DB::table('video')->select($fields)
->where('id',$vid)
->first();

自减

1
2
3
DB::table('product')
->where('id',$pid)
->decrement('gift_amount',$num);

更新

1
2
3
4
DB::table('product')
->where('id',$pid)
->where('amount','<=',0)
->update($fields);

添加返回id

```php
DB::table(‘comment’)
->insertGetId($fields);

js操作json的常用函数

发表于 2019-09-05 | 分类于 前端

JSON.stringify() 从一个对象中解析出字符串

JSON.stringify({“a”:”1”,”b”:”2”})

结果是:”{“a”:”1”,”b”:”2”}”

 

JSON.parse()从一个字符串中解析出JSON对象

var str = ‘{“a”:”1”,”b”:”2”}’;

JSON.parse(str);

结果是:Object{a:”1”,b:”2”}

mysql 随机数&日常用户序列号

发表于 2019-09-05 | 更新于 2022-02-17 | 分类于 IT技术/数据库

日常随机数

1
2
3
4
5
6
7
8
9
10
11
12
//产生0到1000间的随机数 
SELECT RAND() * 10000;

// 增加取整
SELECT FLOOR(RAND() * 10000)

// 产生1000-10000间的整形
SELECT FLOOR( 1000 + RAND() * (10000 - 1000))

// 日常用户序列号,头部参数+1000~9999之间的随机数+时间戳,md5后值

concat('TZ-',md5(concat(FLOOR(1000 + RAND() * (10000 - 1000)),UNIX_TIMESTAMP())))

jquery-ajax常用

发表于 2019-09-05

与后端交互,直接json串,省去传统的一个个参数post

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

// 设定json结构
let postData = {
"userTel": $("#user_info").val(),
"cardSN": cardSN
};

// 生成json
postData = JSON.stringify(postData);

// 提交
$.ajax({
url: URL,
dataType: "json",
type: "post",
data:postData,

// 成功返回
success:function(data){

}
});

php端

1
2
3
4
5
6

// 直接接收
data = trim(file_get_contents('php://input', 'r'));

// 解析
$data = json_decode($data);

layui&jquery-autocomplete组合

发表于 2019-09-04 | 更新于 2019-09-05 | 分类于 前端

layui与jquery-autocomplete 组合使用中的问题

  • 载入问题

远程载入顺序

1
2
3
4
5
6
7
8
9
10
11
<!-- 先jquery -->
<script type="text/javascript" src="images/jquery.min.js"></script>


<!-- layui -->
<link rel="stylesheet" href="images/layui/css/layui.css">
<script type="text/javascript" src="images/layui/layui.all.js"></script>

<!-- jquery插件 -->
<script type="text/javascript" src="images/autocomplete/jquery.autocomplete.js"></script>
<link href="https://cdn.bootcss.com/jquery-autocomplete/1.0.7/jquery.auto-complete.css" rel="stylesheet">
  • layui-form表单
1
2
3
4
5
<!-- 文本框 -->
<input name="card_sn" type="text" autocomplete="off" class="layui-input" lay-verify="required" placeholder="默认提示"/>

<!-- 蓝色普通按钮 -->
<button class="layui-btn layui-btn-normal" lay-filter="card_gen_form" lay-submit>立即提交</button>
  • layui表单提交-ajax+msgbox提示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

layui.use(['jquery', 'layer','laydate','form'], function(){

//日期选择
let laydate = layui.laydate;
laydate.render({
elem: '#start_date' //指定元素
});
laydate.render({
elem: '#end_date' //指定元素
});


// jquery载入
let $ = layui.$
let Url = 'cards.php?rec=gen'
let form = layui.form;

// ajax提交,msgbox显示
form.on('submit(card_gen_form)', function(data){
// layer.msg(JSON.stringify(data.field));
loading = layer.load(1, {
shade: [0.1, '#fff']
});
let card_gen_config = JSON.stringify(data.field);

$.ajax({
type:"post",
url:Url,
data:card_gen_config,
dataType:"json",
success : function(data){
// console.log(data.message);
layer.close(loading);
layer.msg(
data.message,{
time: 2000
});
return false;
},
error:function(){
}
});
return false;
});


});
  • jquery-autocomplete需要被layui调用中的修改问题

打开jquery.autocomplete.js,修改其中的22行,将jquery调用改为用layui中的jquery调用方法

upload successful

修改代码如下

1
2
3
layui.use(['jquery'], function () {
factory(layui.jquery);
});

autocomplete插件与layui弹层问题冲突

1
2
3
4
/*设定z-index置顶*/
.ui-front {
z-index: 110000003;
}
  • layui&jquery-autocomplete组合调用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

layui.use(['jquery','layer','form'], function(){

// 载入jquery

let $=layui.jquery;
$("[id='card_edit']").on("click",function(){
$('#user_info').val('');

// 弹框
let user_sel = layer.open({
type: 1,
title: '手机号&姓名&昵称',
content: $('#user_sel')
});

// 设定高宽
layer.style(user_sel, {
width: '400px',
height: '200px'
});

});


// 文本框输入内容自动检索,每次检索都调用接口
$("#user_info").autocomplete({

source: function( request, response ) {
$.ajax({
url: "cards.php?rec=search",
dataType: "json",
type: "post",
data:{
searchUserInfo: $("#user_info").val()
},
success:function(data){
response(data);
}
});
}
});

});
<i class="fa fa-angle-left" aria-label="上一页"></i>1…10111213<i class="fa fa-angle-right" aria-label="下一页"></i>
Space Yuan

Space Yuan

126 日志
26 分类
72 标签
RSS
<i class="fa fa-fw fa-github"></i>GitHub <i class="fa fa-fw fa-envelope"></i>E-Mail
© 2018 – 2022 Space Yuan