vue_plugins.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /**
  2. * VUE 注册组件
  3. */
  4. Vue.prototype.getVersion = function() {
  5. return "1.2";
  6. };
  7. var template_shopCar = '<div class="aui-shopCar-bg" v-on:click="goToCar">' + '<div class="aui-shop-badge">{{badge}}</div>' + '<div class="zmq-car-text">订单<br />确认</div>' + '</div>';
  8. Vue.component('shopcar', {
  9. props : ["badge"],
  10. template : template_shopCar,
  11. methods : {
  12. goToCar : function() {
  13. // 跳转到购物车页面
  14. this.goWin("orderCar_win", "../order/orderCar_win.html", "");
  15. }
  16. }
  17. })
  18. /**
  19. * 弹出层
  20. */
  21. Vue.component('zmqalert', {
  22. props : ["info"],
  23. template : '<div v-show="info.show"><div class="zmq-model-bg"></div><div class="zmq-prome zmq-bg-white zmq-alert zmq-radius-5"><div class="zmq-alert-title zmq-text-font-09 zmq-text-value zmq-font-weight">{{info.title}}</div><div v-show="info.showMsg" class="zmq-alert-msg zmq-text-value zmq-text-font-06">{{info.msg}}</div><div class="zmq-alert-input zmq-bg-input"><input type="text" placeholder="请按要求填写" v-model = "info.content"/></div><div class="zmq-alert-btn zmq-flex"><div class="zmq-alert-btn-item zmq-flex-1 zmq-textAlign-center" v-on:click="clickAlertBtn(1)">取消</div><div class="zmq-alert-btn-item zmq-flex-1 zmq-textAlign-center" v-on:click="clickAlertBtn(0)">确认</div></div></div></div>',
  24. methods : {
  25. clickAlertBtn : function(type) {
  26. this.info.show = false;
  27. if (type == 0) {
  28. this.$emit("donechoose", type);
  29. }
  30. // 0 点击确认 1 点击取消
  31. }
  32. }
  33. })
  34. /**
  35. * 多选控件
  36. * h : 原先已经有的
  37. * d : 需要渲染的数组
  38. * t : 选择框标题
  39. * n : 触发下拉框的id
  40. */
  41. Vue.prototype.checkByDropdown = function(h, d, t, n, c) {
  42. // document.body.style.position = 'fixed';
  43. document.body.style.overflow = 'hidden';
  44. new Dropdown({
  45. dom : n, //点击触发下拉的选择框的id
  46. type : 'multiple', //是单选还是多选 单选 single 多选 multiple
  47. title : t, //选择框title
  48. required : false, //是否必填
  49. dataArr : d,
  50. success : function(resp) {// 回调函数
  51. // document.body.style.position = 'relative';
  52. // var addList = new Array();
  53. // alert(h.length)
  54. // document.body.style.overflow = 'auto';
  55. // resp.map(function(item,index){
  56. // var has = false;
  57. // h.map(function(ir,ids){
  58. // alert(ir.id + ',' + item.id)
  59. // if(item.id == ir.id){
  60. // has = true;
  61. // }
  62. // })
  63. // if(has == false){
  64. // addList.push(item);
  65. // }
  66. // })
  67. c(resp);
  68. }
  69. })
  70. }
  71. /**
  72. * 将两个JSON对象拼接
  73. */
  74. Vue.prototype.extend = function(a, b) {
  75. for (var obj in b) {
  76. a[obj] = b[obj];
  77. }
  78. return a;
  79. }
  80. // 判断手机号
  81. Vue.prototype.phoneExg = function(phone) {
  82. if (!(/^1[3456789]\d{9}$/.test(phone))) {
  83. return false;
  84. } else {
  85. return true;
  86. }
  87. }
  88. // 判断信息为空
  89. Vue.prototype.checkInfo = function(content) {
  90. if (content == '') {
  91. api.toast({
  92. msg : '必填项不能为空'
  93. });
  94. return false
  95. } else {
  96. return true
  97. }
  98. }
  99. // 判断数组
  100. Vue.prototype.checkArray = function(content) {
  101. if (content.length == 0) {
  102. api.toast({
  103. msg : '必填项不能为空'
  104. });
  105. return false
  106. } else {
  107. return true
  108. }
  109. }
  110. Vue.prototype.checkByDropdown1 = function(h, d, t, n, c) {
  111. // document.body.style.position = 'fixed';
  112. document.body.style.overflow = 'hidden';
  113. new Dropdown({
  114. dom : n, //点击触发下拉的选择框的id
  115. type : 'multiple', //是单选还是多选 单选 single 多选 multiple
  116. title : t, //选择框title
  117. required : false, //是否必填
  118. dataArr : d,
  119. success : function(resp) {// 回调函数
  120. // document.body.style.position = 'relative';
  121. // var addList = new Array();
  122. // alert(h.length)
  123. // document.body.style.overflow = 'auto';
  124. // resp.map(function(item,index){
  125. // var has = false;
  126. // h.map(function(ir,ids){
  127. // alert(ir.id + ',' + item.id)
  128. // if(item.id == ir.id){
  129. // has = true;
  130. // }
  131. // })
  132. // if(has == false){
  133. // addList.push(item);
  134. // }
  135. // })
  136. c(resp);
  137. }
  138. })
  139. }
  140. /**
  141. * 将文字放到图片中生成img
  142. */
  143. Vue.prototype.createImg = function(c){
  144. var canvas2 = document.createElement("canvas");
  145. var _canvas = document.querySelector('div');
  146. var w = parseInt(window.getComputedStyle(_canvas).width);
  147. var h = parseInt(window.getComputedStyle(_canvas).height);
  148. //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
  149. canvas2.width = w * 2;
  150. canvas2.height = h * 2;
  151. canvas2.style.width = w + "px";
  152. canvas2.style.height = h + "px";
  153. //可以按照自己的需求,对context的参数修改,translate指的是偏移量
  154. // var context = canvas.getContext("2d");
  155. // context.translate(0,0);
  156. var context = canvas2.getContext("2d");
  157. context.scale(2, 2);
  158. html2canvas(document.querySelector('div'), { canvas: canvas2 }).then(function(canvas) {
  159. //document.body.appendChild(canvas);
  160. //canvas转换成url,然后利用a标签的download属性,直接下载,绕过上传服务器再下载
  161. c(canvas.toDataURL());
  162. })
  163. }
  164. /**
  165. * VUE 的扩展方法
  166. */
  167. // 获取到的经销商信息
  168. Vue.prototype.userInfo = function() {
  169. this.info = "";
  170. this.loginid = $api.getStorage('loginid');
  171. this.retariler_id = $api.getStorage("retailerid");
  172. this.storeName = $api.getStorage("storeName");
  173. this.carNum = 0;
  174. }
  175. // 使用选择器的时候的数据封装
  176. Vue.prototype.actionSelectorData = function(retlist, c) {
  177. var list = new Array();
  178. retlist.map(function(item, index) {
  179. var option = {
  180. name : eval("item." + c.name),
  181. id : eval("item." + c.id),
  182. }
  183. list.push(option);
  184. })
  185. return list;
  186. }
  187. // 打开筛选页面
  188. /**
  189. * f - 打开页面名称
  190. * s - 打开选择页面还是关闭
  191. * e - 需要传到筛选页面的值
  192. */
  193. var pageStatus = 'o';
  194. Vue.prototype.configDownChoose = function(o, e) {
  195. if (pageStatus == 'o') {
  196. api.openFrame({
  197. name : 'search',
  198. url : '../search.html',
  199. rect : {
  200. x : 0,
  201. y : e.value.h,
  202. w : api.winWidth,
  203. h : api.frameHeight
  204. },
  205. pageParam : {
  206. e : JSON.stringify(e),
  207. o : JSON.stringify(o),
  208. },
  209. bgColor : 'rgba(0,0,0,0)',
  210. animatin : {
  211. type : "movein", //动画类型(详见动画类型常量)
  212. subType : "from_top", //动画子类型(详见动画子类型常量)
  213. duration : 300 //动画过渡时间,默认300毫秒
  214. }
  215. });
  216. pageStatus = 'c';
  217. } else {
  218. pageStatus = 'o';
  219. api.closeFrame({
  220. name : 'search',
  221. });
  222. }
  223. }
  224. // 使用motive配置下拉刷新
  225. Vue.prototype.configHeaderRefush = function(callback) {
  226. api.setCustomRefreshHeaderInfo({
  227. bgColor : '#f2f8f9',
  228. images : ['widget://image/refush1/ru0.png', 'widget://image/refush1/ru1.png', 'widget://image/refush1/ru2.png', 'widget://image/refush1/ru3.png', 'widget://image/refush1/ru4.png', 'widget://image/refush1/ru5.png', 'widget://image/refush1/ru6.png', 'widget://image/refush1/ru7.png'],
  229. // images : ['widget://image/refush1/try.gif'],
  230. tips : {
  231. pull : '下拉刷新',
  232. threshold : '松开立即刷新',
  233. load : '正在刷新'
  234. }
  235. }, function() {
  236. callback();
  237. // //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态
  238. // //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态
  239. // alert('开始加载刷新数据,摇一摇停止加载状态');
  240. // api.addEventListener({
  241. // name : 'shake'
  242. // }, function(ret, err) {
  243. // api.refreshHeaderLoadDone()
  244. // });
  245. });
  246. }
  247. // 配置下拉刷新
  248. Vue.prototype.configHeadMotive = function(callback) {
  249. api.setRefreshHeaderInfo({
  250. visible : true,
  251. bgColor : '#ccc',
  252. textColor : '#fff',
  253. textDown : '下拉刷新...',
  254. textUp : '松开刷新...',
  255. showTime : true
  256. }, function(ret, err) {
  257. if (ret) {
  258. callback(ret);
  259. }
  260. });
  261. }
  262. // 配置下拉刷新
  263. Vue.prototype.configBottomRefush = function(callback) {
  264. new auiScroll({
  265. listen : true,
  266. distance : 0 //判断到达底部的距离,isToBottom为true
  267. }, function(ret) {
  268. if (ret.isToBottom) {
  269. callback(true);
  270. }
  271. });
  272. }
  273. // 配置alert提示框
  274. Vue.prototype.showAlert = function(m, c) {
  275. api.alert({
  276. title : '温馨提示',
  277. msg : m,
  278. buttons : ["确定"],
  279. }, function(ret, err) {
  280. //coding...
  281. c();
  282. });
  283. }
  284. // 延时关闭页面发送监听
  285. Vue.prototype.doneSendEvent = function(n, t, e) {
  286. var times = typeof t == 'undefined' ? 200 : t;
  287. this.sendEvent(n, e);
  288. setTimeout(function() {
  289. api.closeWin({
  290. });
  291. }, times);
  292. }
  293. // 提示信息
  294. Vue.prototype.showToast = function(str) {
  295. api.toast({
  296. msg : str
  297. });
  298. }
  299. // 扫码
  300. Vue.prototype.scan = function(f, c) {
  301. api.showProgress({
  302. title : '请稍候',
  303. text : '正在调起摄像头',
  304. modal : false
  305. });
  306. f.open({
  307. autorotation : true,
  308. isDrawQRCodeRect : true,
  309. }, function(ret, err) {
  310. api.hideProgress();
  311. if (ret) {
  312. if (ret.eventType == 'success') {
  313. c(ret.content);
  314. }
  315. } else {
  316. api.toast({
  317. msg : '扫码出错'
  318. });
  319. }
  320. });
  321. }
  322. // 查看大图
  323. Vue.prototype.lookBigImg = function(f, i) {
  324. f.openImages({
  325. imageUrls : i
  326. });
  327. }
  328. // 扫码 -- 主要是条形码
  329. Vue.prototype.scant = function(f, c) {
  330. var param = {};
  331. var resultCallback = function(ret, err) {
  332. if (ret.eventType == 'success') {
  333. c(ret.content);
  334. }
  335. };
  336. f.openScanner(param, resultCallback);
  337. }
  338. // 输入框类型
  339. Vue.prototype.showPromt = function(title, msg, buttons, callback) {
  340. api.prompt({
  341. title : title,
  342. msg : msg,
  343. buttons : buttons
  344. }, function(ret, err) {
  345. //coding...
  346. callback(ret);
  347. });
  348. }
  349. // 注册监听
  350. Vue.prototype.addEvent = function(eventName, callback) {
  351. api.addEventListener({
  352. name : eventName,
  353. }, function(ret, err) {
  354. //coding...
  355. callback(ret);
  356. });
  357. }
  358. // 提示信息
  359. Vue.prototype.showModal = function(title, msg, buttons, callback) {
  360. api.confirm({
  361. title : title,
  362. msg : msg,
  363. buttons : buttons,
  364. }, function(ret, err) {
  365. //coding...
  366. callback(ret.buttonIndex);
  367. });
  368. }
  369. // 过滤掉数组中的对象
  370. Vue.prototype.filterArrNotNull = function(s, a) {
  371. return s.filter(a == null)
  372. }
  373. // 发送监听
  374. Vue.prototype.sendEvent = function(eventName, params) {
  375. api.sendEvent({
  376. name : eventName,
  377. extra : params
  378. });
  379. }
  380. // 跳转页面
  381. Vue.prototype.goWin = function(winName, winUrl, params) {
  382. setTimeout(function() {
  383. api.openWin({
  384. name : winName,
  385. url : winUrl,
  386. pageParam : params,
  387. bounces : false,
  388. animation : {
  389. type : "push", //动画类型(详见动画类型常量)
  390. subType : "from_right", //动画子类型(详见动画子类型常量)
  391. duration : 300 //动画过渡时间,默认300毫秒
  392. }
  393. });
  394. }, 200);
  395. }
  396. // 点击查看大图
  397. Vue.prototype.lookBigImage = function(a, srcs) {
  398. a.openImages({
  399. imageUrls : srcs
  400. });
  401. }
  402. // 选择图片
  403. Vue.prototype.chooseImage = function(c) {
  404. var _this = this;
  405. // 判断是相机还是图片库
  406. api.actionSheet({
  407. title : '选择附件',
  408. cancelTitle : '这里是取消按钮',
  409. buttons : ['相机', '相册']
  410. }, function(ret, err) {
  411. if (ret.buttonIndex == 3) {
  412. return;
  413. }
  414. var imageT = _this.imageType[ret.buttonIndex];
  415. _this.startChooseImage(imageT, function(path) {
  416. c(path);
  417. });
  418. });
  419. }
  420. // 开始选择图片
  421. Vue.prototype.startChooseImage = function(imageT, callback) {
  422. var _this = this;
  423. api.getPicture({
  424. sourceType : imageT,
  425. encodingType : 'png',
  426. mediaValue : 'pic',
  427. destinationType : 'url',
  428. allowEdit : true,
  429. quality : 100,
  430. // targetWidth : 100,
  431. // targetHeight : 100,
  432. saveToPhotoAlbum : false
  433. }, function(ret, err) {
  434. if (ret) {
  435. if (ret.data != "") {
  436. // 有选择的相片了
  437. // _this.imgs = ret.data;
  438. callback(ret.data);
  439. }
  440. } else {
  441. alert(JSON.stringify(err));
  442. }
  443. });
  444. }
  445. // 关闭页面
  446. Vue.prototype.closeWin = function() {
  447. setTimeout(function() {
  448. api.closeWin({
  449. });
  450. }, 200);
  451. }
  452. // 点击选择省市区
  453. Vue.prototype.chooseRegion = function(UIActionSelector, col, datasUrl, callback) {
  454. UIActionSelector.open({
  455. datas : datasUrl,
  456. layout : {
  457. row : 5,
  458. col : col,
  459. height : 30,
  460. size : 12,
  461. sizeActive : 14,
  462. rowSpacing : 5,
  463. colSpacing : 10,
  464. maskBg : 'rgba(0,0,0,0.2)',
  465. bg : '#fff',
  466. color : '#ddd',
  467. colorActive : '#f00',
  468. colorSelected : '#000'
  469. },
  470. animation : true,
  471. cancel : {
  472. text : '取消',
  473. size : 12,
  474. w : 90,
  475. h : 35,
  476. bg : '#fff',
  477. bgActive : '#ccc',
  478. color : '#888',
  479. colorActive : '#fff'
  480. },
  481. ok : {
  482. text : '确定',
  483. size : 12,
  484. w : 90,
  485. h : 35,
  486. bg : '#fff',
  487. bgActive : '#ccc',
  488. color : '#888',
  489. colorActive : '#fff'
  490. },
  491. title : {
  492. text : '请选择',
  493. size : 12,
  494. h : 44,
  495. bg : '#eee',
  496. color : '#888',
  497. },
  498. fixedOn : api.frameName
  499. }, function(ret, err) {
  500. if (ret) {
  501. if (ret.eventType == 'ok') {
  502. callback(ret);
  503. }
  504. } else {
  505. api.toast({
  506. msg : '事件错误'
  507. });
  508. }
  509. });
  510. }
  511. // 显示加载框
  512. Vue.prototype.showProcess = function() {
  513. api.showProgress({
  514. title : '请稍候...',
  515. text : '加载中...'
  516. });
  517. }
  518. // 隐藏加载框
  519. Vue.prototype.hideProcess = function() {
  520. api.hideProgress();
  521. }
  522. // 获取用户信息
  523. Vue.prototype.getUserInfo = function(callback) {
  524. var url = "getUserInfoUrl", loginid = $api.getStorage('loginid'), _this = this;
  525. var data = {
  526. loginId : loginid,
  527. url : 'json',
  528. type : 'body',
  529. };
  530. this.$post(url, data, function(ret) {
  531. if ( typeof callback != 'undefined' && callback != "undefined" && callback != "") {
  532. callback(ret);
  533. }
  534. if (ret.retailerDto != null) {
  535. // 将retariler_id和username保存起来
  536. $api.setStorage('retailerid', ret.retailerDto.id);
  537. $api.setStorage('storeName', ret.retailerDto.storeName);
  538. }
  539. });
  540. }
  541. // 获取购物车数量
  542. Vue.prototype.getCarNum = function(id, callback) {
  543. var data = {
  544. retailer_id : id,
  545. }, url = "shopCarListUrl", _this = this;
  546. this.$post(url, data, function(ret) {
  547. if (ret.code == 0) {
  548. _this.userInfo.carNum = ret.list.length;
  549. callback(ret.list);
  550. }
  551. })
  552. }
  553. // 获取新版本,然后下载安装
  554. Vue.prototype.getNewVersionUrl = function() {
  555. var data = {
  556. paramKey : 'shop_url',
  557. url : 'json',
  558. type : 'body'
  559. }, url = "getVersionUrl", _this = this;
  560. this.$post(url, data, function(ret) {
  561. if (ret.code == 0) {
  562. _this.downLoadApp(ret.version);
  563. }
  564. })
  565. }
  566. // 下载版本
  567. Vue.prototype.downLoadApp = function(url) {
  568. var _this = this;
  569. api.showProgress({
  570. title : "更新提示",
  571. text : "正在更新",
  572. modal : false
  573. });
  574. // if (app.uav_type == 'IOS') {
  575. // api.installApp({
  576. // appUri : app.uav_filepath
  577. // });
  578. // } else {
  579. api.download({
  580. url : url,
  581. savePath : '',
  582. report : true,
  583. cache : true,
  584. allowResume : true
  585. }, function(re, err) {
  586. if (re.state == 1) {
  587. api.hideProgress();
  588. api.installApp({
  589. appUri : re.savePath
  590. });
  591. } else if (re.state == 2) {
  592. callback('fail')
  593. }
  594. })
  595. //}
  596. }
  597. // 获取
  598. /******** ajax请求 ********/
  599. Vue.prototype.$post = function(url, data, callback, other) {
  600. var http = new $http();
  601. http.$post(url, data, function(ret) {
  602. if (ret.code == 0) {
  603. callback(ret);
  604. } else {
  605. api.toast({
  606. msg : ret.msg
  607. });
  608. }
  609. }, other)
  610. }
  611. Vue.prototype.$get = function(url, data, callback, other) {
  612. var http = new $http();
  613. http.$get(url, data, function(ret) {
  614. if (ret.code == 0) {
  615. callback(ret);
  616. } else {
  617. api.toast({
  618. msg : ret.msg
  619. });
  620. }
  621. }, other)
  622. }
  623. Vue.prototype.$getadd = function(url, data, callback, other){
  624. var http = new $http();
  625. http.$getadd(url, data, function(ret) {
  626. if (ret.code == 0) {
  627. callback(ret);
  628. } else {
  629. api.toast({
  630. msg : ret.msg
  631. });
  632. }
  633. }, other)
  634. }