| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <!doctype html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>我的资料</title>
- <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
- <link href="../css/mui.min.css" rel="stylesheet" />
- <link href="../css/style.css" rel="stylesheet" />
- <style type="text/css">
- .head {
- height: 40px;
- }
-
- #head {
- line-height: 40px;
- }
-
- .head-img {
- width: 40px;
- height: 40px;
- }
-
- #head-img1 {
- position: absolute;
- bottom: 10px;
- right: 40px;
- width: 40px;
- height: 40px;
- }
-
- .mui-fullscreen {
- position: fixed;
- z-index: 20;
- background-color: #000;
- }
-
- .mui-content {
- position: absolute;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- }
- </style>
- </head>
- <body>
- <header class="mui-bar mui-bar-nav" style="padding-right: 15px;color: #fff; background-color: #cd0000 !important;">
- <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #FFFFFF;"></a>
- <h1 class="mui-center mui-title"><span class="Totle-box">我的头像</span><span class="Totle"></span></h1>
- </header>
- <div class="mui-content">
- <ul class="mui-table-view">
- <li class="mui-table-view-cell">
- <a id="head" class="mui-navigate-right">个人头像
- <span class="mui-pull-right head">
- <img class="head-img mui-action-preview" id="head-img1" src=""/>
- </span>
- </a>
- </li>
- </ul>
- <div class="mui-input-row mui-margin-vertical">
- <h5 class="mui-margin-horizontal-xs">个人签名:</h5>
- <input class="mui-padding-lg" id="signature" type="text" placeholder="个人签名" />
- </div>
- </div>
- <script src="../js/mui.min.js"></script>
- <script src="../js/app.js"></script>
- <script type="text/javascript">
- (function($) {
- mui.init({
- swipeBack: true
- });
- $.plusReady(function() {
- //初始化头像,和预览图
- setTimeout(function() {
- defaultInfo();
- setTimeout(function() {
- initImgPreview();
- }, 200);
- }, 0);
- //弹出菜单
- mui(".mui-table-view-cell").on("tap", "#head", function(e) {
- if(mui.os.plus) {
- var a = [{
- title: "拍照"
- }, {
- title: "从手机相册选择"
- }];
- plus.nativeUI.actionSheet({
- title: "修改头像",
- cancel: "取消",
- buttons: a
- }, function(b) {
- switch(b.index) {
- case 0:
- break;
- case 1:
- getImage();
- break;
- case 2:
- galleryImg();
- break;
- default:
- break
- }
- })
- }
- });
-
- });
- //拍照
- function getImage() {
- var c = plus.camera.getCamera();
- c.captureImage(function(e) {
- //存储到本地
- plus.io.resolveLocalFileSystemURL(e, function(entry) {
- cutImage(entry.toLocalURL());
- }, function(e) {
- console.log("读取拍照文件错误:" + e.message);
- });
- }, function(s) {
- console.log("error" + s);
- }, {
- filename: "_doc/head.jpg"
- })
- }
- //相册
- function galleryImg() {
- plus.gallery.pick(function(a) {
- plus.io.resolveLocalFileSystemURL(a, function(entry) { //entry为图片原目录(相册)的句柄
- cutImage(entry.toLocalURL());
- }, function(e) {
- console.log("读取图片错误:" + e.message);
- });
- }, function(a) {}, {
- filter: "image"
- })
- };
- //设置默认头像
- function defaultInfo() {
- var my_icon = app.getHeadImg(); //头像
- var signature = app.getUserInfo().signature; //签名
- if(my_icon && my_icon != "") {
- document.getElementById("head-img1").src = my_icon;
- } else {
- document.getElementById("head-img1").src = '../img/3.png';
- }
- if(signature && signature != "") {
- document.getElementById("signature").value = signature;
- } else {
- document.getElementById("signature").value = "";
- }
- }
- //预览图像
- document.getElementById("head-img1").addEventListener('tap', function(e) {
- e.stopPropagation(); //阻止冒泡
- });
- function initImgPreview() {
- var imgs = document.querySelectorAll("img.mui-action-preview");
- imgs = mui.slice.call(imgs);
- if(imgs && imgs.length > 0) {
- var slider = document.createElement("div");
- slider.setAttribute("id", "__mui-imageview__");
- slider.classList.add("mui-slider");
- slider.classList.add("mui-fullscreen");
- slider.style.display = "none";
- slider.addEventListener("tap", function() {
- slider.style.display = "none";
- });
- slider.addEventListener("touchmove", function(event) {
- event.preventDefault();
- })
- var slider_group = document.createElement("div");
- slider_group.setAttribute("id", "__mui-imageview__group");
- slider_group.classList.add("mui-slider-group");
- imgs.forEach(function(value, index, array) {
- //给图片添加点击事件,触发预览显示;
- value.addEventListener('tap', function() {
- slider.style.display = "block";
- _slider.refresh();
- _slider.gotoItem(index, 0);
- })
- var item = document.createElement("div");
- item.classList.add("mui-slider-item");
- var a = document.createElement("a");
- var img = document.createElement("img");
- img.setAttribute("src", value.src);
- a.appendChild(img)
- item.appendChild(a);
- slider_group.appendChild(item);
- });
- slider.appendChild(slider_group);
- document.body.appendChild(slider);
- var _slider = mui(slider).slider();
- }
- }
- //裁剪图片
- function cutImage(path) {
- $.openWindow({
- url: 'index.html',
- id: 'index',
- extras: {
- path: path,
- },
- show: {
- aniShow: 'zoom-fade-in',
- duration: 800
- },
- waiting: {
- autoShow: true
- }
- });
- }
- //更新用户头像
- function update_head_img(e) {
- var my_icon = e.detail.img;
- //先上传
- app.request("User", "saveHeadImg", {
- 'my_icon': my_icon
- }, function(res) {
- if(res.login == 0) {
- mui.toast(res.info);
- app.clearToken();
- app.toLogin();
- return false;
- }
- if(res.status == 1) {
- app.setHeadImg(my_icon); //确认上传成功后存储到本地
- if(my_icon == "")
- my_icon = "../img/3.png";
- document.getElementById("head-img1").src = my_icon; //刷新小图
- document.querySelector("#__mui-imageview__group .mui-slider-item img").src = my_icon; //刷新预览图
- //顺带触发上一个页面的updateHeadInfo
- var view = plus.webview.getWebviewById("index");
- $.fire(view, "updateHeadInfo");
- mui.toast(res.info);
- } else {
- mui.toast(res.info);
- }
- });
- }
- window.addEventListener("updateHeadImg", update_head_img); //添加自定义事件,其他页面调用
- })(mui);
- </script>
- </body>
- </html>
|