使用APICloud AVM框架开发人事档案管理助手APP

APICloud模块的引入、服务器数据对接,APP数据存储方式  1.模块的使用和引用 在apicloud的模块store里面提供了大量的模块,我们可以直接在html里面引入使用 使用方法:在需要使用模块的页面中加入: var obj = api.require('模块名'); 然后参考对应模块的使用方法。如果在一个页面中频繁使用到一个模块的功能,最好就将其声明称全局变量。 2.服务器数据对接---云数据库和本地服务器 1.、 阅读详情

由于人事档案具有涉密性,所以本应用没有使用后台服务,全部功能都在APP本地实现。

数据库采用sqllite,没有使用UI框架,个人觉得AVM本身支持的flex布局配合自写CSS样式,完全可以实现市面上所有的UI框架的元素,这个取决于个人功力。

思维脑图

功能介绍:

1.人员花名册

2.编制情况

3.个人中心

技术要点:

手势密码验证,本地数据库操作,语音播报。

开发工具采用 APICloud Studio3,基于VSCode的(PS:比基于Atom的autio2好用太多);

应用模块:

项目文件目录:

 引用一下官方的关于目录结构的介绍

 开发介绍

首页导航

系统首页使用tabLayout,可以将相关参数配置在JSON文件中,再在config.xml中将content的值设置成该JSON文件的路径。如果底部导航没有特殊需求这里强烈建议大家使用tabLayout为APP进行布局,官方已经将各类手机屏幕及不同的分辨率进行了适配,免去了很多关于适配方面的问题。

app.json文件内容,关于json文件的命名是没有限制的,我习惯用app。

{
    "name": "root",
    "textOffset": 6,
    "color": "#999999",
    "selectedColor": "#006aff",
    "scrollEnabled": false,
    "hideNavigationBar": false,
    "bgColor": "#fff",
    "navigationBar": {
        "background": "#006aff",
        "shadow": "rgba(0,0,0,0)",
        "color": "#fff",
        "fontSize": 18,
        "hideBackButton": true
    },
    "tabBar": {
      "background": "#fff",
      "shadow": "#eee",
      "color": "#5E5E5E",
      "selectedColor": "#006aff",
      "textOffset": 3,
      "fontSize": 11,
      "scrollEnabled": true,
      "index": 1,
      "preload": 0,
      "frames": [
        {
          "title": "编制情况",
          "name": "home",
          "url": "./pages/records/organ"
        },
        {
          "title": "人员花名册",
          "name": "course",
          "url": "./pages/person/organ"
        },
        {
          "title": "个人中心",
          "name": "user",
          "url": "./pages/main/main"
        }
      ],
      "list": [
        {
          "text": "编制",
          "iconPath": "./image/authoried-o.png",
          "selectedIconPath": "./image/authoried.png"
        },
        {
          "text": "人员",
          "iconPath": "./image/person-o.png",
          "selectedIconPath": "./image/person.png"
        },
        {
          "text": "我的",
          "iconPath": "./image/user-o.png",
          "selectedIconPath": "./image/user.png"
        }
      ]
    }
  }

列表显示及分页

通过上拉刷新和下拉操作,配合JS方法实现分页查询功能。

<template name='list'>
    <scroll-view scroll-y class="main" enable-back-to-top refresher-enabled refresher-triggered={refresherTriggered} onrefresherrefresh={this.onrefresherrefresh} onscrolltolower={this.onscrolltolower}>
		<view class="item-box">
			<view class="item" data-id={item.id} v-for="(item, index) in personList" tapmode onclick="openTab">
				<image class="avator" src={item.photo} mode="widthFix"></image>
				<text class="item-title">{item.name}</text>
				<text class="item-sub-title">{item.nation}</text>
			</view>
		</view>
		<view class="footer">
			<text class="loadDesc">{loadStateDesc}</text>
		</view>		
    </scroll-view>
</template>
<script>
	import $util from "../../utils/utils.js"
	export default {
		name: 'list',	
		data() {
			return{
				personList:[],
				skip: 0,
				refresherTriggered: false,
				haveMoreData: true,
				loading: false,
				organid:0
			}
		},
		computed: {			
			loadStateDesc(){
				if (this.data.loading || this.data.haveMoreData) {
					return '加载中...';
				} else if (this.personList.length > 0) {
					return '没有更多啦';
				} else {
					return '暂时没有内容';
				}
			}
		},
		methods: {
			apiready(){
				this.data.organid = api.pageParam.id;
				this.loadData(false);
				//更换头像
				api.addEventListener({
					name: 'setavator'
				}, (ret, err) => {
					this.loadData();
				});
				//新增人员信息
				api.addEventListener({
					name: 'addperson'
				}, (ret, err) => {
					this.loadData();
				});
				//删除人员信息
				api.addEventListener({
					name: 'delperson'
				}, (ret, err) => {
					this.loadData();
				});
				if(api.getPrefs({sync: true,key: 'role'})=='99'){
					//添加编辑按钮
					api.setNavBarAttr({
						rightButtons: [{
							text: '新增'
						}]
					});
					//监听右上角按钮点击事件
					api.addEventListener({
						name: 'navitembtn'
					}, (ret, err) => {
						if (ret.type == 'right') {
							$util.openWin({
								name: 'personadd',
								url: 'personadd.stml',
								title: '新增人员信息',
								pageParam:{
									organid:this.data.organid
								}
							});
						}
					});
				}			
			},
			loadData(loadMore) {
				if (this.data.loading) {
					return;
				}
				api.showProgress();
				this.data.loading = true;
				var limit = 15;
				var skip = loadMore?(this.data.skip+1)*limit:0;

				// console.log('select id,name,grade,sex,nation,photo from authority where organ = '+this.data.organid+' order by id limit '+limit+' offset '+skip);

				var db = api.require('db');
				db.selectSql({
					name: 'doc',
					sql: 'select id,name,grade,sex,nation,photo from authorized where organ = '+this.data.organid+' order by id limit '+limit+' offset '+skip
				}, (ret, err)=> {
					// console.log(JSON.stringify(ret));
					// console.log(JSON.stringify(err));
					if (ret.status) {
						let records = ret.data;
						this.data.haveMoreData = records.length == limit;
						if (loadMore) {
							this.data.personList = this.data.personList.concat(records);
						} else {
							this.data.personList = records;
						}
						this.data.skip = skip;
					} else {
						this.data.recordsList = records;
						api.toast({
							msg:err.msg
						})
					}
					this.data.loading = false;
					this.data.refresherTriggered = false;
					api.hideProgress();
				});
			},
			/*下拉刷新页面*/
			onrefresherrefresh(){
				this.data.refresherTriggered = true;
				this.loadData(false);
			},
			onscrolltolower() {
				if (this.data.haveMoreData) {
					this.loadData(true);
				}
			},
			openTab(e){
				let id = e.currentTarget.dataset.id;
				$util.openWin({
					name: "personinfo",
					url: 'personinfo.stml',
					title: '人员信息',
					pageParam:{
						id:id
					}
				});
			}
		}
	}
</script>

表单提交

采用AVM自带的from控件,通过onsubmit进行数据提交

头像图片上传及base64转码

由于是本地sqllite数据库,人员头像图片需要转成base64编码存储到数据库中。通过官方模块trans进行图片转码操作。

<image class="avator" src={this.data.src} mode="widthFix"  onclick="setavator"></image>

            setavator(){
				api.actionSheet({
					cancelTitle: '取消',
					buttons: ['拍照', '打开相册']
				}, (ret, err) => {
					if (ret.buttonIndex == 3) {
						return false;
					}
					var sourceType = (ret.buttonIndex == 1) ? 'camera' : 'album';
					api.getPicture({
						sourceType: sourceType,
						allowEdit: true,
						quality: 20,
						destinationType:'url'
					}, (ret, err) => {
						if (ret && ret.data) {
							var trans = api.require('trans');
							trans.decodeImgToBase64({
								imgPath: ret.data
							}, (ret, err) => {
								// console.log(JSON.stringify(ret));
								// console.log(JSON.stringify(err));
								if (ret.status) {
									let b64 =  "data:image/jpeg;base64,"+ret.base64Str;
									this.data.src = b64;
								} else {
									api.toast({
										msg:'照片上传失败,请重新选择!'
									})
								}
							});
						}
					});
				});
			},

sqllite数据库 db模块

由于数据库文件需要存储的应用安装文件中,所有需要官方fs模块配合使用来进行数据库文件的操作。

copyDB(){
            var fs = api.require('fs');
            fs.copyTo({
                oldPath: 'widget://db/doc.db',
                newPath: 'fs://db'
            }, function(ret, err) {
                // console.log(JSON.stringify(ret));
                // console.log(JSON.stringify(err));
                if (ret.status) {
                    // console.log(JSON.stringify(ret));
                    api.toast({
                        msg:'拷贝数据库成功!'
                    })
                } else {
                    // console.log(JSON.stringify(err));
                    api.toast({
                        msg:JSON.stringify(err)
                    })
                }
            });
        },
        openDB(){
            var db = api.require('db');
            db.subfile({
                directory:'fs://db'
            }, (ret, err)=> {
                // console.log(JSON.stringify(ret));
                // console.log(JSON.stringify(err));
                if (ret.status) {
                    // console.log(JSON.stringify(ret));
                    //打开数据库
                    db.openDatabase({
                        name: 'doc',
                        path: ret.files[0]
                    }, (ret, err)=> {
                        // console.log(JSON.stringify(ret));
                        // console.log(JSON.stringify(err));
                        if (ret.status) {
                            // console.log(JSON.stringify(ret));
                            api.toast({
                                msg:'打开数据库成功!'
                            })
                        } else {
                            // console.log(JSON.stringify(err));
                            api.toast({
                                msg:JSON.stringify(err)
                            })
                        }
                    });
                    
                } else {
                    // console.log(JSON.stringify(err));
                    api.toast({
                        msg:JSON.stringify(err)
                    })
                }
            });
        },
        closeDB(){
            var db = api.require('db');
            db.closeDatabase({
                name: 'doc'
            }, function(ret, err) {
                if (ret.status) {
                    console.log(JSON.stringify(ret));
                    api.toast({
                        msg:'关闭数据库成功'
                    })
                } else {
                    // console.log(JSON.stringify(err));
                    api.toast({
                        msg:JSON.stringify(err)
                    })
                }
            });
        },
        updateDB(){
            var fs = api.require('fs');
            var db = api.require('db');
            db.closeDatabase({
                name: 'doc'
            }, (ret, err) => {
                if (ret.status) {
                    //拷贝文件
                    fs.copyTo({
                        oldPath: 'widget://doc.db',
                        newPath: 'fs://db/'
                    }, (ret, err) => {
                        if (ret.status) {
                             db.subfile({
                                directory:'fs://db'
                            }, (ret, err)=> {
                                if(ret.status){
                                    //打开数据库
                                    db.openDatabase({
                                        name: 'doc',
                                        path: ret.files[0]
                                    }, (ret, err)=> {
                                        if (ret.status) {
                                            api.toast({
                                                msg:'数据库更新成功!'
                                            })
                                        } else {
                                            api.toast({
                                                msg:JSON.stringify(err)
                                            })
                                        }
                                    });
                                }
                                else{
                                    api.toast({
                                        msg:JSON.stringify(err)
                                    })
                                }                              
                            })
                        } else {
                            api.toast({
                                msg:JSON.stringify(err)
                            })
                        }
                    });
                } else {
                    api.toast({
                        msg:JSON.stringify(err)
                    })
                }
            }); 
        },

语音播报功能

采用官方提供的IFLyVoice模块,需要注意的是,基础资源文件和发音人资源文件(.jet文件)需要到科大讯飞开发者平台进行下载导入的项目中。还有对数字的解读不是精确,尤其是年份,最好不要用数字,而是用中文。

//添加朗读按钮
					api.setNavBarAttr({
						rightButtons: [{
							text: '朗读'
						}]
					});
					//监听右上角按钮点击事件
					api.addEventListener({
						name: 'navitembtn'
					}, (ret, err) => {
						// console.log(JSON.stringify(this.data.info));
						if (ret.type == 'right') {
							var IFlyVoice = api.require('IFlyVoice');
							IFlyVoice.initSpeechSynthesizer((ret)=>{
							//   console.log(JSON.stringify(ret));
							});
							IFlyVoice.startSynthetic({
								text:this.data.info,
								commonPath_Android:'widget://res/android/common.jet',
								pronouncePath_Android:'widget://res/android/xiaoyan.jet',
								pronounceName:'xiaoyan',
								speed:40
							},(ret,err)=>{
								// console.log(JSON.stringify(ret));
								// console.log(JSON.stringify(err));
								if (ret.status) {
									// console.log('合成成功');
								} else {
									// console.log(JSON.stringify(err));
								}
							});
						}
					});

手势密码保护

手势密码保护由于官方模块存在样式问题,及原生模块存在遮罩问题,所以采用了平台上提供的H5模块。APICloud强大之处在这里进行了淋漓尽致的体现,通过AVM及原生模块无法实现的功能,可以再用H5的方式来实现!牛逼!!!!,通过设置全局变量来记录是否已设置手机密码,每次应用启动通过这个变量来判断是否开启手势密码保护。

this.data.islock =api.getPrefs({sync: true,key: 'islock'});
				if(this.data.islock=='Y'){
					api.openFrame({
						name: 'h5lock',
						url:'../../html/h5lock.html'
					})
				}
				else{
					api.toast({
						msg:'您还没有设置手势密码,为了数据安全,请尽快设置。'
					})
				}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>H5lock</title>
    <style type="text/css">
        body {
            text-align: center;
            background-color: #000000;
        }
        .title {
            /*color: #87888a;*/
            margin-top: 85px;
            font-size: 20px;
            font-weight:lighter;
        }
    </style>
</head>
<body>
<script type="text/javascript" src="../script/H5lock.js"></script>
<script type="text/javascript">
    var opt = {
        chooseType: 3, // 3 , 4 , 5,
        width: 300, // lock wrap width
        height: 300, // lock wrap height
        container: 'element', // the id attribute of element
        inputEnd: function (psw){} // when draw end param is password string
    }
    var lock = new H5lock(opt);
    lock.init();
</script>
</body>
</html>
(function(){
        window.H5lock = function(obj){
            this.height = obj.height;
            this.width = obj.width;
            this.chooseType = Number(window.localStorage.getItem('chooseType')) || obj.chooseType;
            this.devicePixelRatio = window.devicePixelRatio || 1;
        };


        H5lock.prototype.drawCle = function(x, y) { // 初始化解锁密码面板 小圆圈
            this.ctx.strokeStyle = '#87888a';//密码的点点默认的颜色
            this.ctx.lineWidth = 2;
            this.ctx.beginPath();
            this.ctx.arc(x, y, this.r, 0, Math.PI * 2, true);
            this.ctx.closePath();
            this.ctx.stroke();
        }
        H5lock.prototype.drawPoint = function(style) { // 初始化圆心
            for (var i = 0 ; i < this.lastPoint.length ; i++) {
                this.ctx.fillStyle = style;
                this.ctx.beginPath();
                this.ctx.arc(this.lastPoint[i].x, this.lastPoint[i].y, this.r / 2.5, 0, Math.PI * 2, true);
                this.ctx.closePath();
                this.ctx.fill();
            }
        }
        H5lock.prototype.drawStatusPoint = function(type) { // 初始化状态线条
            for (var i = 0 ; i < this.lastPoint.length ; i++) {
                this.ctx.strokeStyle = type;
                this.ctx.beginPath();
                this.ctx.arc(this.lastPoint[i].x, this.lastPoint[i].y, this.r, 0, Math.PI * 2, true);
                this.ctx.closePath();
                this.ctx.stroke();
            }
        }
        H5lock.prototype.drawLine = function(style, po, lastPoint) {//style:颜色 解锁轨迹
            this.ctx.beginPath();
            this.ctx.strokeStyle = style;
            this.ctx.lineWidth = 3;
            this.ctx.moveTo(this.lastPoint[0].x, this.lastPoint[0].y);

            for (var i = 1 ; i < this.lastPoint.length ; i++) {
                this.ctx.lineTo(this.lastPoint[i].x, this.lastPoint[i].y);
            }
            this.ctx.lineTo(po.x, po.y);
            this.ctx.stroke();
            this.ctx.closePath();

        }
        H5lock.prototype.createCircle = function() {// 创建解锁点的坐标,根据canvas的大小来平均分配半径

            var n = this.chooseType;
            var count = 0;
            this.r = this.ctx.canvas.width / (1 + 4 * n);// 公式计算
            this.lastPoint = [];
            this.arr = [];
            this.restPoint = [];
            var r = this.r;
            for (var i = 0 ; i < n ; i++) {
                for (var j = 0 ; j < n ; j++) {
                    count++;
                    var obj = {
                        x: j * 4 * r + 3 * r,
                        y: i * 4 * r + 3 * r,
                        index: count
                    };
                    this.arr.push(obj);
                    this.restPoint.push(obj);
                }
            }
            this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
            for (var i = 0 ; i < this.arr.length ; i++) {
                this.drawCle(this.arr[i].x, this.arr[i].y);
            }
            //return arr;
        }
        H5lock.prototype.getPosition = function(e) {// 获取touch点相对于canvas的坐标
            var rect = e.currentTarget.getBoundingClientRect();
            var po = {
                x: (e.touches[0].clientX - rect.left)*this.devicePixelRatio,
                y: (e.touches[0].clientY - rect.top)*this.devicePixelRatio
              };
            return po;
        }
        H5lock.prototype.update = function(po) {// 核心变换方法在touchmove时候调用
            this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);

            for (var i = 0 ; i < this.arr.length ; i++) { // 每帧先把面板画出来
                this.drawCle(this.arr[i].x, this.arr[i].y);
            }

            this.drawPoint('#27AED5');// 每帧花轨迹
            this.drawStatusPoint('#27AED5');// 每帧花轨迹

            this.drawLine('#27AED5',po , this.lastPoint);// 每帧画圆心

// if (this.lastPoint.length == 4) {
//     // debugger
// }

            for (var i = 0 ; i < this.restPoint.length ; i++) {
                if (Math.abs(po.x - this.restPoint[i].x) < this.r && Math.abs(po.y - this.restPoint[i].y) < this.r) {
                    this.drawPoint(this.restPoint[i].x, this.restPoint[i].y);
                    this.lastPoint.push(this.restPoint[i]);
                    this.restPoint.splice(i, 1);
                    break;
                }
            }

        }
        H5lock.prototype.checkPass = function(psw1, psw2) {// 检测密码
            var p1 = '',
            p2 = '';
            for (var i = 0 ; i < psw1.length ; i++) {
                p1 += psw1[i].index + psw1[i].index;
            }
            for (var i = 0 ; i < psw2.length ; i++) {
                p2 += psw2[i].index + psw2[i].index;
            }
            return p1 === p2;
        }
        H5lock.prototype.storePass = function(psw) {// touchend结束之后对密码和状态的处理

            if (this.pswObj.step == 1) {
                if (this.checkPass(this.pswObj.fpassword, psw)) {
                    this.pswObj.step = 2;
                    this.pswObj.spassword = psw;
                    document.getElementById('title').innerHTML = '密码保存成功';                                   

                    this.drawStatusPoint('#2CFF26');
                     this.drawPoint('#2CFF26');
                    window.localStorage.setItem('passwordxx', JSON.stringify(this.pswObj.spassword));
                    window.localStorage.setItem('chooseType', this.chooseType);

                } else {
                    document.getElementById('title').innerHTML = '两次不一致,重新输入';
                    this.drawStatusPoint('red');
                     this.drawPoint('red');
                    delete this.pswObj.step;
                }
            } else if (this.pswObj.step == 2) {
                if (this.checkPass(this.pswObj.spassword, psw)) {
                    var title = document.getElementById("title");
                    title.style.color = "#2CFF26";
                    title.innerHTML = '解锁成功';

                    this.drawStatusPoint('#2CFF26');//小点点外圈高亮
                    this.drawPoint('#2CFF26');
                    this.drawLine('#2CFF26',this.lastPoint[this.lastPoint.length-1] , this.lastPoint);// 每帧画圆心

                    api.closeFrame();
                    

                } else if (psw.length < 4) {
                    
                    this.drawStatusPoint('red');
                    this.drawPoint('red');
                    this.drawLine('red',this.lastPoint[this.lastPoint.length-1] , this.lastPoint);// 每帧画圆心

                    var title = document.getElementById("title");
                    title.style.color = "red";
                    title.innerHTML = '请连接4个点';

                } else {
                    this.drawStatusPoint('red');
                    this.drawPoint('red');
                    this.drawLine('red',this.lastPoint[this.lastPoint.length-1] , this.lastPoint);// 每帧画圆心


                    var title = document.getElementById("title");
                    title.style.color = "red";
                    title.innerHTML = '手势密码错误,请重试';
                }
            } else {
                this.pswObj.step = 1;
                this.pswObj.fpassword = psw;
                document.getElementById('title').innerHTML = '再次输入';
            }

        }
        H5lock.prototype.makeState = function() {
            if (this.pswObj.step == 2) {
                // document.getElementById('updatePassword').style.display = 'block';
                //document.getElementById('chooseType').style.display = 'none';

                var title = document.getElementById("title");
                title.style.color = "#87888a";
                title.innerHTML = '请解锁';

            } else if (this.pswObj.step == 1) {
                //document.getElementById('chooseType').style.display = 'none';
                // document.getElementById('updatePassword').style.display = 'none';
            } else {
                // document.getElementById('updatePassword').style.display = 'none';
                //document.getElementById('chooseType').style.display = 'block';
            }
        }
        H5lock.prototype.setChooseType = function(type){
            chooseType = type;
            init();
        }
        H5lock.prototype.updatePassword = function(){
            window.localStorage.removeItem('passwordxx');
            window.localStorage.removeItem('chooseType');
            this.pswObj = {};
            document.getElementById('title').innerHTML = '绘制解锁图案';
            this.reset();
        }
        H5lock.prototype.initDom = function(){
            var wrap = document.createElement('div');
            var str = '<h4 id="title" class="title" style="color:#87888a">请绘制您的图形密码</h4>';

            wrap.setAttribute('style','position: absolute;top:0;left:0;right:0;bottom:0;');
            var canvas = document.createElement('canvas');
            canvas.setAttribute('id','canvas');
            canvas.style.cssText = 'background-color: #000;display: inline-block;margin-top: 76px;';
            wrap.innerHTML = str;
            wrap.appendChild(canvas);

            var width = this.width || 320;
            var height = this.height || 320;
            
            document.body.appendChild(wrap);

            // 高清屏锁放
            canvas.style.width = width + "px";
            canvas.style.height = height + "px";
            canvas.height = height * this.devicePixelRatio;
            canvas.width = width * this.devicePixelRatio;
            

        }
        H5lock.prototype.init = function() {
            this.initDom();
            this.pswObj = window.localStorage.getItem('passwordxx') ? {
                step: 2,
                spassword: JSON.parse(window.localStorage.getItem('passwordxx'))
            } : {};
            this.lastPoint = [];
            this.makeState();
            this.touchFlag = false;
            this.canvas = document.getElementById('canvas');
            this.ctx = this.canvas.getContext('2d');
            this.createCircle();
            this.bindEvent();
        }
        H5lock.prototype.reset = function() {
            this.makeState();
            this.createCircle();
        }
        H5lock.prototype.bindEvent = function() {
            var self = this;
            this.canvas.addEventListener("touchstart", function (e) {
                e.preventDefault();// 某些android 的 touchmove不宜触发 所以增加此行代码
                 var po = self.getPosition(e);

                 for (var i = 0 ; i < self.arr.length ; i++) {
                    if (Math.abs(po.x - self.arr[i].x) < self.r && Math.abs(po.y - self.arr[i].y) < self.r) {

                        self.touchFlag = true;
                        self.drawPoint(self.arr[i].x,self.arr[i].y);
                        self.lastPoint.push(self.arr[i]);
                        self.restPoint.splice(i,1);
                        break;
                    }
                 }
             }, false);
             this.canvas.addEventListener("touchmove", function (e) {
                if (self.touchFlag) {
                    self.update(self.getPosition(e));
                }
             }, false);
             this.canvas.addEventListener("touchend", function (e) {
                 if (self.touchFlag) {
                     self.touchFlag = false;
                     self.storePass(self.lastPoint);
                     setTimeout(function(){

                        self.reset();
                    }, 1000);
                 }


             }, false);

            //  document.getElementById('updatePassword').addEventListener('click', function(){
            //      self.updatePassword();
            //   });
        }
})();

 设置手势密码

登录成功之后,在个人中心来设置手势密码。可通过参数设置来初始化密码强度。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>H5lock</title>
    <style type="text/css">
        body {
            text-align: center;
            background-color: #000000;
        }
        .title {
            /*color: #87888a;*/
            margin-top: 85px;
            font-size: 20px;
            font-weight:lighter;
        }
        .reset{
            position: relative;
            top: 200px;
            font-size: 20px;
            text-align: center;
        }
    </style>
</head>
<body>
<script type="text/javascript" src="../script/setH5lock.js"></script>
<script type="text/javascript">
    var opt = {
        chooseType: 3, // 3 , 4 , 5,
        width: 300, // lock wrap width
        height: 300, // lock wrap height
        container: 'element', // the id attribute of element
        inputEnd: function (psw){} // when draw end param is password string
    }
    var lock = new H5lock(opt);
    lock.init();
</script>
</body>
</html>

修改密码

系统默认设定了用户的初始密码,用户登录系统后会提示进行密码修改,修改后的密码进行了MD5加密,由于没有后台系统,所以密码的MD5加密,采用了JS来进行加密。通过开发工具调试控制台安装js插件

安装成功之后会在文件目录中显示

然后在用的地方直接引入即可。

import $md5 from '../../node_modules/js-md5/build/md5.min.js'
 var db = api.require('db');
                    db.executeSql({
                        name: 'doc',
                        sql: "update user set password = '"+ md5(ret.text) +"' where id = 1"
                    }, (ret, err)=> {
                        // console.log(JSON.stringify(ret));
                        // console.log(JSON.stringify(err));
                        if (ret.status) {
                            api.alert({
                                title: '消息提醒',
                                msg: '密码修改成功,请重新登陆',
                            }, (ret, err) => {
                                //清除用户信息
                                api.removePrefs({
                                    key: 'username'
                                });
                                api.removePrefs({
                                    key: 'userid'
                                });
                                api.removePrefs({
                                    key: 'password'
                                });	
                                $util.openWin({
                                    name: 'login',
                                    url: '../main/login.stml',
                                    title: '',
                                    hideNavigationBar:true
                                });
                            });
                        } else {						
                            api.toast({
                                msg:JSON.stringify(err)
                            })
                        }
                    });

 封装工具类插件 utils.js

在需要用到插件中通用方法的地方,直接引用即可。

import $util from "../../utils/utils.js"
const $util = {
    openWin(param){
        var param = {
            name: param.name,
            url: param.url,
            title: param.title||'',
            pageParam: param.pageParam||{},
            hideNavigationBar: param.hideNavigationBar || false,
            navigationBar:{
                background:'#1492ff',
                shadow: '#fff',
                color: '#fff'
            }
        };
        if (this.isApp()) {
            api.openTabLayout(param);
        } else {
            api.openWin(param);
        }
    },
    isApp(){
        if (api.platform && api.platform == 'app') {
            return true;
        }
        return false;
    },
    fitRichText(richtext, width){
        var str = `<img style="max-width:${width}px;"`;
        var result = richtext.replace(/\<img/gi, str);
        return result;
    },
    isLogin(){
        if(api.getPrefs({sync: true,key: 'userid'})){
            return true;
        }
        return false;
    },
    openDataBase(){
        var fs = api.require('fs');
        var db = api.require('db');
        db.subfile({
            directory:'fs://db'
        }, (ret, err)=> {
            if(ret.status){
                //打开数据库
                db.openDatabase({
                    name: 'doc',
                    path: ret.files[0]
                }, (ret, err)=> {
                    if (ret.status) {
                        // api.toast({
                        //     msg:'打开数据库成功!'
                        // })
                    } else {
                        api.toast({
                            msg:JSON.stringify(err)
                        })
                    }
                });
            }
            else{
                //拷贝文件
                fs.copyTo({
                    oldPath: 'widget://doc.db',
                    newPath: 'fs://db/'
                }, function(ret, err) {
                    if (ret.status) {
                        db.subfile({
                            directory:'fs://db'
                        }, (ret, err)=> {
                            if(ret.status){
                                //打开数据库
                                db.openDatabase({
                                    name: 'doc',
                                    path: ret.files[0]
                                }, (ret, err)=> {
                                    if (ret.status) {

                                    } else {
                                        api.toast({
                                            msg:JSON.stringify(err)
                                        })
                                    }
                                });
                            }
                            else{
                                api.toast({
                                    msg:JSON.stringify(err)
                                })
                            }
                        })   
                    } else {
                        api.toast({
                            msg:JSON.stringify(err)
                        })
                    }
                });
            }
        })
    }
}
export default $util;

用户功能权限

系统分为2级用户,管理员账号和领导账号。通过角色ID进行区分,管理员账号有信息的增删改查功能,领导账号只有信息的查询功能。

用于登录成功之后将用户信息进行缓存。

//登陆APP
			submit() {				
				api.showProgress();
				// console.log( "select id,username,password from user where username = '"+this.data.user+"' and password = '"+md5(this.data.psw)+"'");
				var db = api.require('db');
				db.selectSql({
					name: 'doc',
					sql: "select id,username,password,role from user where username = '"+this.data.user+"' and password = '"+md5(this.data.psw)+"'"
				}, (ret, err)=> {
					// console.log(JSON.stringify(ret));
					// console.log(JSON.stringify(err));
					if (ret.status) {
						if(ret.data.length==1){
							api.setPrefs({key:'username',value:ret.data[0].username});
							api.setPrefs({key:'userid',value:ret.data[0].id});
							api.setPrefs({key:'password',value:ret.data[0].password});
							api.setPrefs({key:'role',value:ret.data[0].role});

							api.sendEvent({
								name: 'loginsuccess',
							});
							api.closeWin();
						}
						else{
							api.toast({
								msg:'登陆失败,请输入正确的用户名和密码'
							})
						}
						
					} else {						
						api.toast({
							msg:JSON.stringify(err)
						})
					}
					api.hideProgress();
				});
			}

在需要验证用户权限的地方通过获取角色ID,进行逻辑判断。

if(api.getPrefs({sync: true,key: 'role'})=='99'){
					//添加编辑按钮
					api.setNavBarAttr({
						rightButtons: [{
							text: '编辑'
						}]
					});
					//监听右上角按钮点击事件
					api.addEventListener({
						name: 'navitembtn'
					}, (ret, err) => {
						if (ret.type == 'right') {
							$util.openWin({
								name: 'personedit',
								url: 'personedit.stml',
								title: '人员信息编辑',
								pageParam:{
									id:this.data.id
								}
							});
						}
					});
				}
				else{
					//添加朗读按钮
					api.setNavBarAttr({
						rightButtons: [{
							text: '朗读'
						}]
					});
					//监听右上角按钮点击事件
					api.addEventListener({
						name: 'navitembtn'
					}, (ret, err) => {
						// console.log(JSON.stringify(this.data.info));
						if (ret.type == 'right') {
							var IFlyVoice = api.require('IFlyVoice');
							IFlyVoice.initSpeechSynthesizer((ret)=>{
							//   console.log(JSON.stringify(ret));
							});
							IFlyVoice.startSynthetic({
								text:this.data.info,
								commonPath_Android:'widget://res/android/common.jet',
								pronouncePath_Android:'widget://res/android/xiaoyan.jet',
								pronounceName:'xiaoyan',
								speed:40
							},(ret,err)=>{
								// console.log(JSON.stringify(ret));
								// console.log(JSON.stringify(err));
								if (ret.status) {
									// console.log('合成成功');
								} else {
									// console.log(JSON.stringify(err));
								}
							});
						}
					});
				}

双击退出应用程序

应用如果不做任何处理,在应用初始页面出发keyback事件,会弹出提示框提示是否退出程序,体验感极差。针对此进行了优化,由于应用首页采用了tablayout,所以只需要在tablayout默认选中项的索引页面中添加双击keyback事件的监听,并通过api.toast进行提示。

在登录页面也需要添加此监听,应为用户退出登录之后,会自动跳转至登录页,如果不做处理,用户点击物理返回键就会导致用户在没有登录的情况下跳回上一页。加了此监听事件用户点击返回键不做处理,双击会提示退出程序。

//监听返回  双击退出程序
				api.setPrefs({
					key: 'time_last',
					value: '0'
				});
				api.addEventListener({
					name : 'keyback'
					}, (ret, err) => {
					var time_last = api.getPrefs({sync: true,key: 'time_last'});
					var time_now = Date.parse(new Date());
					if (time_now - time_last > 2000) {
						api.setPrefs({key:'time_last',value:time_now});
						api.toast({
							msg : '再按一次退出APP',
							duration : 2000,
							location : 'bottom'
						});
					} else {
						api.closeWidget({
							silent : true
						});
					}
				});

应用动态权限

安卓10之后,对应用的权限要求提高,不在像老版本一样配置上就会自动获取,必须进行提示。

依据官方给出的教程进行了动态权限的设置。

1.添加 mianfest.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
    <application name="targetSdkVersion" value="28"/>
</manifest>

在系统索引页进行动态权限获取提醒,本系统只涉及到了文件存储权限的获取,如需要获取多个权限,在List[]数组中继续添加需要的权限,然后根据添加的权限个数,做相应的几个判断即可。

let limits=[];
				//获取权限
				var resultList = api.hasPermission({
					list: ['storage']
				});
				if (resultList[0].granted) {
					// 已授权,可以继续下一步操作
				} else {
					limits.push(resultList[0].name);
				}
				if(limits.length>0){
					api.requestPermission({
						list: limits,
					}, (res) => {
						
					});
				}

使用apicloud完成消息推送功能 apicloud是一款用html5封装的手机端的一个东西,消息推送就是我们经常说的手机打开一个软件后,该软件会出现相应的消息显示在通知栏,例如这样                                                              怎么才能实现呢,其实完成下面几步就ok了 1、在极光推送网站( https://www.jpush.cn )注册 阅读详情

相关推荐

apicloud 从服务器获取数据 数据库数据

apiready = function(){ function getlist(){ api.showProgress(); api.ajax({ url: 'http://47.92.121.222/t/index.php/index/index/getlist', method: 'post', data: { values: { name: 'haha' }, files: { file:

木匠专栏 3814

全局变量与storage的区别

微信小程序 及 apicloud 全局变量为一个总变量 在各个文件中使用 一直存在直到关闭页面为止 storage是存储在手机的缓存内部 即得到了一遍只要不清除缓存 可持续使用 一般用于登录的信息保存 ...

qq_41619567的博客 604

Arm Neoverse CMN-700 QoS与PrefetchTarget架构解析

在现代多核处理器系统中,内存访问性能优化是提升整体效能的关键。QoS(服务质量)技术通过优先级调控机制,确保关键任务获得更高的缓存带宽和内存访问权限。PrefetchTarget作为预取技术的一种实现,能够显著降低内存访问延迟,特别适用于AI训练和数据库系统等高性能计算场景。Arm Neoverse CMN-700通过RN SAM模块实现了硬件级的地址范围检测和优先级调控,支持最多8个独立内存区域的QoS配置。测试数据显示,合理配置QoS可使关键任务延迟降低40%,而PrefetchTarget技术则能减少

weixin_36197669的博客 314

新手入门教程,从0开始入手APIcloud(二)

前面一篇主要讲了项目的创建和布局方式。总结一下APP的布局方式最佳为win+frame,多写个文件多弄点优化才能让你的APP流畅度提高。这篇主要来讲一下模块的引入、服务器数据对接及APP数据存储方式。一、模块的引入和使用在apicloud的模块store里面提供了大量的模块,我们可以直接在html里面引入使用使用方法:在需要使用模块的页面中加入:var obj = api.require('模块名...

lsxf_xin的专栏 2万+

libiec61850实战:手把手教你用C语言动态获取IED设备模型(附完整代码解析)

本文详细介绍了如何使用libiec61850库通过C语言动态获取IED设备模型,包括环境配置、连接建立、模型遍历及错误处理等关键步骤。通过完整的代码示例和实战案例,帮助开发者掌握智能变电站通信中的核心技术,提升工业自动化系统的开发效率。

weixin_42519985的博客 433

PCB激光直接成像(LDI)设备技术解析与优化方案

激光直接成像(LDI)是PCB制造中的关键数字化工艺,通过激光束直接在基板上形成电路图案。其核心技术在于高精度光学系统与智能控制算法的结合,工作精度可达微米级。在HDI板、柔性电路等高端PCB制造中,LDI技术能显著提升线宽精度和层间对位准确性。当前行业面临材料适配性、热变形控制等挑战,动态能量补偿、多波长曝光等创新方案正在突破这些瓶颈。随着模块化设计、预测性维护等工程实践的普及,LDI设备综合效率持续提升,为5G、汽车电子等领域的精密电路生产提供关键技术支撑。

weixin_29168393的博客 391

APICloud Studio3 API管理与调试使用教程

简介面板功能区介绍根据途中红色数字编号,对应功能如下:API、请求变量定义面板切换搜索框与新增按钮API列表(列表中的每个文件夹称为一个分类)根据API生成代码API详情、从左至右依次为请求method、url与发送请求按钮request区域response区域变量配置面板创建API创建API的方式两种:通过搜索框右侧"+"按钮创建:将鼠标移入按钮会弹出操作面板,点击新建API方法,会弹出编辑API名称弹窗,输入API名称点击"确定"即可在对应的分类下成功创建通过分类右侧"..."按钮创建:选择一个分类后,

cuicuiniu521的博客 1243

Orcad原理图导入Allegro

在即将设计的PCB中,将层叠设置好后,执行File→import→parameters,将刚才导出的.prm文件导入,很多参数就自动设置好了,与已完成的PCB里的参数保持一致。具体操作是:在已完成的PCB里执行File→Exoprt→Parameters,弹出下图所示的对话框,选择需要导出的设计参数后,设置到导出路径,导出记录设计参数的文件(.prm)。在.brd文件导入网表后,往往需要页面大小、格点、各层叠里各要素显示颜色等参数,手动设置十分麻烦,我们可以在一块已经完成的PCB里导出记录设计参数的文件。

sinat_27007097的博客 2085

apicloud的使用

APICloud官方文档地址:https://docs.apicloud.com/APICloud/creating-first-app ——————安装studio和AppLoader—————— 1、直接安装apicloud studio2(不要搞什么sublime的插件了,太麻烦。) 2、安装jdk,百度搜索jdk(java开发运行环境),并下载和安装。 3、手机安装...

aogouqian7476的博客 507

Nature风格的北半球投影图,几行代码就能绘制...

在子刊***Nat. Clim. Chang.***中,通过北极俯视投影表示NAO和AO的EOF分解。仅在定义图层的时候设置为该投影,其余设置content,绘制contourf都是PlateCaree。如子刊Nature Geosci中表示了海冰的漂移,还添加了DEM底图,非常美观。以海温数据为例,ERA5月温度平均,是一张721*1440的0.25degTIF。现在的结果看起来不错,但太大了,我们如果只需要北半球的数据,则需要指定经纬度。绘制完结果也是正方形,和ArcGIS差不多,见之前的推文。

wlh2067的博客 1292

视图库对接系列(GA-T 1400)一、简单介绍

GA/T 1400《公安视频图像信息应用系统》 是我们需要参考看看的相关文档,里面有对应的标准和介绍,没有这个文档的话可以加群找我要。群的话 我放在最下面了。我们先简单想几个问题, 也就是这个协议主要干什么用的,为什么要有, 能做什么。

qq_37716298的博客 4285

apiCloud中引用vue.js的用法

关于apiCloud中引用vue.js的用法@584186328@qq.com 在apiCloud中引用vue.js主要是使用vue的双向数据绑定,vue模块可添加在 apiready中生效,添加vue后,初始化页面的函数需要在created中执行,代码如下: apiready = function () { var app = new Vue({ el: '#myApp'...

weixin_43368635的博客 1394

GEE:本地影像上传到GEE的Assets中,并输入机器学习算法中作为特征变量

当我们在 Google Earth Engine(GEE)中应用机器学习算法时,会输入一些影像作为特征变量数据,进一步根据这些特征影像去推理未知区域的数据。但是 GEE 平台上计算特征变量的 API 函数并不是非常全面,我们希望获得更多的特征用于分类。这个时候,我们可以将本地计算的特征影像上传到 GEE 中进行后续处理。本文记录了从本地上传特征数据到 GEE 的 Assets 中的教程,用于后续在 GEE 中分类或者回归使用。本文也可作为《》一文的补充。

养乐多的博客 1730

APICloud AVM框架 开发视频会议APP

1.创建会议,确认会议时间、参会人员、会议主题、确定会议主持人(默认为发起人)可开启会议;同时会通过应用消息和短信通知参会人员。2.加入会议,可通过会议大厅找的会议列表直接加入,也可通过输入会议编号加入会议;加入会议的前提是会议已在进行中。3.快速会议,可直接确认会议人员然后发起实时视频会议,参会人员实时接收应用消息或短信,快速进入会议。3.历史会议,分为我主持的会议、我参与的会议。4.会议大厅,列表显示今天需要参加的会议。......

白鱼赤乌的博客 800

蓝牙调试抓包工具--nRF Connect移动端 使用详细总结

摘要: nRF Connect移动端是一款功能全面的蓝牙低功耗(BLE)调试工具,支持设备扫描、多设备连接、服务/特征值查看及数据读写操作。核心功能包括实时数据通信(读取/写入/通知)、设备固件更新(DFU)以及高级工具如自动化测试和信号分析。兼容Android 4.3+和iOS设备,适用于开发调试(如ESP32/nRF52)、设备管理和数据分析。需注意设备兼容性问题(如旧安卓设备可能需关闭连续扫描),并确保数据类型匹配。配套工具链包括nRF Toolbox和nRF Connect SDK,是BLE开发的必

AIoT深度探索者 | 嵌入式系统架构师 深耕物联网(IoT)与人工智能(AI)融合技术,聚焦​​边缘计算、图像开发、低功耗通信协议​​,致力于智能硬件,关注我获取最新技术文章信息与海量资源~ 2380

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

apicloud中页面之间传递数据

只写最简单 ,最容易懂得例子 就不如说一个列表 &lt;ul id="ld-left"&gt; &lt;li v-for='item in list' @click='show(item.id)'&gt;{{item.title}}&lt;/li&gt; &lt;/ul&gt; 这里的list数据就不用说了吧 ,后台直接拿到数据,放在Vue的data中 比如我们点击相应...

社会人 1万+

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

vue中使用apicloud时遇到的问题

最近用vue做了一个网站,网站里有分享,支付等功能。因为需要在app中调用这个网站,但跟同事沟通知道APP是用apicloud做的,支付分享等这些功能都需要使用APP的接口去做。所以牵涉到在vue页面中使用apicloud去做功能。 一、判断是否是APP 网站原先的逻辑不变,只需要在APP的情况下去请求APP接口写一套逻辑。这就需要判断网站当前环境是否是APP。 最先使用的是vue的页面中,在mounted函数里写了这样一段代码: 然后在methods中写了一个函数 想着在APP的环境下改

SPN_迪的博客 1143

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Apicloud常见问题建议方案

Apicloud常见问题建议方案 取消ios手机号自动识别 ======================================================== 消除ajax跨域问题 使用官方提供的api.ajax方法 =====================================================

tezhg的博客 1627

APICloud 获取服务器数据的两种方法(自己的服务器和APICloud 的云服务器)

一、通过api.ajax异步请求取个人服务器数据 apiready = function(){ api.ajax({ url: 'http://119.29.157.60/api/Shop/getAll', // 自己用PHP写的请求数据库的接口 method: 'get', headers:{ 'Content-Type': 'appli...

qq_35445741的博客 3838

APICloud教程

一、通过APICloud进行App前端布局和数据交互App前端布局:Window :窗口Frame:子窗口FrameGroup:一组子窗口的集合 window+frame+html代码的布局方式整个页面最外面是一个window,头部和导航固定不变,为一个frame,下方内容区域又是一个frame,整个frame里面就是具体的页面内容了,里面嵌套了html\css代码 打开新窗口的过程,就是在一组w...

weixin_34149796的博客 1万+

apicloud常见问题总结。

(一)apicloud的$api和api有什么区别?$api是apicloud的js框架,类似jquery中的选择器符号 api是指apicloud的端api对象(打包调用原生属性或方法)(二)apicloud开发app如何设置推送 引入push模块就可以了。var push = api.require('push');//设置推送 push.setListener(functi

bluemengcom的博客 3508

mybatis设置全局变量

开发时遇到mapper.xml sql中本地表和线上表有差异、用户不用,导致切换改来改去特别费事,就增加了全局变量 mybatis-config.xml &lt;!-- 自定义全局变量设置 --&gt; &lt;properties&gt; &lt;!-- 本地测试 --&gt; &lt;property name="auth_db_user" value=""/&gt; &l

ardo_pass的博客 3943

APICloud 实践 —— 安装与创建应用

1.安装APICloud Studio 下载地址:https://www.apicloud.com/devtools   2.打开 APICloud Studio,登录   3.登录成功,在 代码编辑器 创建应用 或者 云端创建应用。 编辑器创建应用如下图:   如果没有出现上面的欢迎页,就通过 文件 --》 新建 --》 APICloud 移动应用 创建:   里面的一些配置可查看官网:h...

weixin_33709364的博客 690
下一篇: APICloud AVM框架 封装日历组件
白鱼赤乌
博客等级 码龄10年 7粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白鱼赤乌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值