vue-module.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. $(document).ready(function(){
  2. //登录组件 login
  3. Vue.component('login',{
  4. template:`
  5. <div type="login" v-on:click="on.button.exit()" v-bind:style="style.box" align="center">
  6. <div v-bind:style="style.frame">
  7. <label v-bind:style="style.label">
  8. <span v-bind:style="style.head">登录</span>
  9. </label>
  10. <label v-bind:style="style.label">
  11. <span v-bind:style="style.i">*</span>
  12. <span v-bind:style="style.title">账号</span>
  13. <input maxlength="9" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  14. </label>
  15. <span v-bind:style="style.info"></span>
  16. <label v-bind:style="style.label">
  17. <span v-bind:style="style.i">*</span>
  18. <span v-bind:style="style.title">密码</span>
  19. <input maxlength="16" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  20. </label>
  21. <span v-bind:style="style.info"></span>
  22. <label v-bind:style="style.label">
  23. <button v-on:click="on.button.QR_code()" v-bind:style="[style.button,style.button[2]]">扫码</button>
  24. <button v-on:click="on.button.login()" v-bind:style="[style.button,style.button[2]]">登录</button>
  25. <button v-on:click="on.button.exit()" type="quit" v-bind:style="[style.button,style.button[1]]">关闭</button>
  26. </label>
  27. <label v-bind:style="style.qr.box">
  28. <img v-bind:style="style.qr.img" width="100" height="100" alt=""/>
  29. <br/>
  30. <button v-on:click="on.button.account_login()" v-bind:style="style.qr.button" >账号登录</button>
  31. </label>
  32. </div>
  33. </div>`,
  34. data:function () {
  35. return {
  36. style:{
  37. box:{
  38. width:'100%',
  39. height:'100%',
  40. position:'fixed',
  41. zIndex:$('*').length * 2,
  42. background:'rgba(0,0,0,.2)'
  43. },
  44. frame:{
  45. display:'inline-grid',
  46. position: 'absolute',
  47. top:0,
  48. bottom:0,
  49. left:0,
  50. right:0,
  51. margin:'auto',
  52. width:'300px',
  53. height:'200px',
  54. borderRadius:'2.5px',
  55. padding:'20px 50px',
  56. background: '#FFF',
  57. },
  58. label:{
  59. height:'30px',
  60. },
  61. head:{
  62. lineHeight: '24px',
  63. fontSize: '18px',
  64. color: '#303133',
  65. },
  66. i:{
  67. color:'red',
  68. },
  69. title:{
  70. letterSpacing: '2.5px',
  71. marginRight:'5px',
  72. fontSize:'14px',
  73. color: '#606266',
  74. height:'30px',
  75. lineHeight:'30px',
  76. },
  77. input:{
  78. padding: '5px 10px',
  79. width: '200px',
  80. height: '20px',
  81. border:'1px solid #c3c3c3',
  82. borderRadius: '2.5px',
  83. outline:'none',
  84. },
  85. button:{
  86. cursor:'pointer',
  87. marginRight: '15px',
  88. float:'right',
  89. height:'30px',
  90. width:'70px',
  91. border:'none',
  92. borderRadius:'2.5px',
  93. outline: 'none',
  94. 1:{
  95. border:'1px solid #c3c3c3',
  96. background:'#FFF',
  97. color:'black'
  98. },
  99. 2:{
  100. border:'1px solid #409EFF',
  101. background:'#409EFF',
  102. color:'#FFF'
  103. }
  104. },
  105. info:{
  106. textAlign:'left',
  107. margin:'0 70px',
  108. height:'15px',
  109. letterSpacing:'2px',
  110. lineHeight: '15px',
  111. color:'red',
  112. fontSize: '10px',
  113. },
  114. qr:{
  115. box:{
  116. display:'none',
  117. height:'150px',
  118. },
  119. img:{
  120. borderRadius:'2.5px',
  121. },
  122. button:{
  123. cursor: 'pointer',
  124. marginTop:'15px',
  125. height:'30px',
  126. background:'#FFF',
  127. border:'1px solid #c3c3c3',
  128. outline:'none',
  129. width:'150px',
  130. }
  131. }
  132. },
  133. on:{
  134. input:{
  135. focus:function () {
  136. event.target.style.borderColor = '#409EFF';
  137. },
  138. blur:function () {
  139. var input = event.target;
  140. var info = $(input).parent('label').next('span')[0];
  141. var title = $(input).prev('span')[0].innerText;
  142. if ($(input).val() === defaultStatus||$(input).val()===null){
  143. info.innerText = title+'不能为空';
  144. } else if ($(input).val().indexOf(' ') !== -1){
  145. info.innerText = title+'不能包含空格';
  146. } else {
  147. info.innerText = '';
  148. }
  149. input.style.borderColor = '#c3c3c3';
  150. }
  151. },
  152. button:{
  153. exit:function () {
  154. if ($("div[type='login']").is(event.target) || $("button[type='quit']").is(event.target)){
  155. $("div[type='login']").css('display','none');
  156. }
  157. },
  158. login:function () {
  159. var message = $(event.target).parent('label').prevAll('label');
  160. var account = $(message[1]).find('input').val();
  161. var password = $(message[0]).find('input').val();
  162. var account_info = $(message[1]).next('span')[0];
  163. var password_info = $(message[0]).next('span')[0];
  164. var account_title = $(message[1]).find('span').eq(1).text();
  165. var password_title = $(message[0]).find('span').eq(1).text();
  166. if (account === defaultStatus||account===null){
  167. account_info.innerText = account_title+'不能为空';
  168. } else if (account.indexOf(' ') !== -1){
  169. account_info.innerText = account_title+'不能包含空格';
  170. }
  171. if (password === defaultStatus||password ===null){
  172. password_info.innerText = password_title+'不能为空';
  173. } else if (password.indexOf(' ') !== -1){
  174. password_info.innerText = password_title+'不能包含空格';
  175. }
  176. if (account !== defaultStatus
  177. &&account!==null
  178. &&account.indexOf(' ') === -1
  179. &&password !== defaultStatus
  180. &&password !==null
  181. &&password.indexOf(' ') === -1){
  182. POST('login',{
  183. account:account,
  184. password:password,
  185. },function (data) {
  186. alert_s(data.msg);
  187. if (data.error === 1){
  188. $.cookie('uuid',data.uuid,{exports:15});
  189. document.location.href = document.location.href;
  190. }
  191. })
  192. }
  193. },
  194. QR_code:function(){
  195. let qr_info = {
  196. time:new Date(),
  197. }
  198. alert_s('功能暂不支持');
  199. $(event.target).parent('label').next('label').find('img').attr('src','http://qrs.kegood.com/?url='+JSON.stringify(qr_info))
  200. $(event.target).parent('label').parent('div').find('label').css('display','none')
  201. $(event.target).parent('label').prevAll('span').text('')
  202. $(event.target).parent('label').parent('div').find('label')[0].style.display = 'block';
  203. $(event.target).parent('label').parent('div').find('label')[4].style.display = 'block';
  204. },
  205. account_login:function () {
  206. $(event.target).parent('label').parent('div').find('label').css('display','block')
  207. $(event.target).parent('label').parent('div').find('label')[4].style.display = 'none';
  208. }
  209. }
  210. }
  211. };
  212. }
  213. });
  214. //注册组件 logon
  215. Vue.component('logon',{
  216. template:`
  217. <div type="login" v-on:click="on.button.exit()" v-bind:style="style.box" align="center">
  218. <input accept=".jpg,.png,.jpeg" type="file" hidden="hidden"/>
  219. <div v-bind:style="style.frame">
  220. <label v-bind:style="style.label">
  221. <span v-bind:style="style.head">注册</span>
  222. </label>
  223. <label v-bind:style="style.label.portrait">
  224. <span v-bind:style="style.i">*</span>
  225. <span v-bind:style="[style.title,{marginRight:'0px'}]">头像</span>
  226. <div v-on:mousedown="on.button.file" v-bind:style="style.portrait.box">
  227. <i v-bind:style="style.portrait.x"></i>
  228. <i v-bind:style="style.portrait.y"></i>
  229. </div>
  230. </label>
  231. <span v-bind:style="style.info"></span>
  232. <label v-bind:style="style.label">
  233. <span v-bind:style="style.i">*</span>
  234. <span v-bind:style="style.title">昵称</span>
  235. <input maxlength="9" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  236. </label>
  237. <span v-bind:style="style.info"></span>
  238. <label v-bind:style="style.label">
  239. <span v-bind:style="style.i">*</span>
  240. <span v-bind:style="style.title">密码</span>
  241. <input maxlength="16" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  242. </label>
  243. <span v-bind:style="style.info"></span>
  244. <label v-bind:style="style.label">
  245. <span v-bind:style="style.i">*</span>
  246. <span v-bind:style="style.title">邮箱</span>
  247. <input type="email" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  248. </label>
  249. <span v-bind:style="style.info"></span>
  250. <label v-bind:style="style.label">
  251. <button v-on:click="on.button.logon()" v-bind:style="[style.button,style.button[2]]">注册</button>
  252. <button v-on:click="on.button.exit()" type="quit" v-bind:style="[style.button,style.button[1]]">关闭</button>
  253. </label>
  254. </div>
  255. </div>`,
  256. data:function () {
  257. return {
  258. style:{
  259. box:{
  260. width:'100%',
  261. height:'100%',
  262. position:'fixed',
  263. zIndex:$('*').length * 2,
  264. background:'rgba(0,0,0,.2)',
  265. },
  266. frame:{
  267. display:'inline-grid',
  268. position: 'absolute',
  269. top:0,
  270. bottom:0,
  271. left:0,
  272. right:0,
  273. margin:'auto',
  274. width:'300px',
  275. height:'350px',
  276. borderRadius:'2.5px',
  277. padding:'20px 50px',
  278. background: '#FFF',
  279. },
  280. label:{
  281. height:'30px',
  282. portrait:{
  283. marginTop:'10px',
  284. width:'100%',
  285. height:'70px',
  286. lineHeight:'70px',
  287. }
  288. },
  289. head:{
  290. lineHeight: '24px',
  291. fontSize: '18px',
  292. color: '#303133',
  293. },
  294. i:{
  295. color:'red',
  296. },
  297. title:{
  298. letterSpacing: '2.5px',
  299. marginRight:'5px',
  300. fontSize:'14px',
  301. color: '#606266',
  302. height:'30px',
  303. lineHeight:'30px',
  304. },
  305. input:{
  306. padding: '5px 10px',
  307. width: '200px',
  308. height: '20px',
  309. border:'1px solid #c3c3c3',
  310. borderRadius: '2.5px',
  311. outline:'none',
  312. },
  313. portrait:{
  314. box:{
  315. float:'right',
  316. position:'relative',
  317. marginRight:'163px',
  318. width:'70px',
  319. height:'70px',
  320. backgroundRepeat:'no-repeat',
  321. backgroundPosition:'center center',
  322. backgroundSize:'100% 100%',
  323. outline:'1px dotted #c3c3c3'
  324. },
  325. x:{
  326. left:'15px',
  327. right:'15px',
  328. top:'0px',
  329. bottom:'0px',
  330. margin:'auto',
  331. position:'absolute',
  332. height:'1px',
  333. background:'#c3c3c3',
  334. },
  335. y:{
  336. left:'0px',
  337. right:'0px',
  338. top:'15px',
  339. bottom:'15px',
  340. margin:'auto',
  341. position:'absolute',
  342. width:'1px',
  343. background:'#c3c3c3',
  344. }
  345. },
  346. button:{
  347. cursor:'pointer',
  348. marginRight: '15px',
  349. float:'right',
  350. height:'30px',
  351. width:'70px',
  352. border:'none',
  353. borderRadius:'2.5px',
  354. outline: 'none',
  355. 1:{
  356. border:'1px solid #c3c3c3',
  357. background:'#FFF',
  358. color:'black'
  359. },
  360. 2:{
  361. border:'1px solid #409EFF',
  362. background:'#409EFF',
  363. color:'#FFF'
  364. }
  365. },
  366. info:{
  367. textAlign:'left',
  368. margin:'0 70px',
  369. height:'15px',
  370. letterSpacing:'2px',
  371. lineHeight: '15px',
  372. color:'red',
  373. fontSize: '10px',
  374. },
  375. qr:{
  376. box:{
  377. display:'none',
  378. height:'150px',
  379. },
  380. img:{
  381. borderRadius:'2.5px',
  382. },
  383. button:{
  384. cursor: 'pointer',
  385. marginTop:'15px',
  386. height:'30px',
  387. background:'#FFF',
  388. border:'1px solid #c3c3c3',
  389. outline:'none',
  390. width:'150px',
  391. }
  392. }
  393. },
  394. on:{
  395. input:{
  396. focus:function () {
  397. event.target.style.borderColor = '#409EFF';
  398. },
  399. blur:function () {
  400. var input = event.target;
  401. var info = $(input).parent('label').next('span')[0];
  402. var title = $(input).prev('span')[0].innerText;
  403. if ($(input).val() === defaultStatus||$(input).val()===null){
  404. info.innerText = title+'不能为空';
  405. } else if ($(input).val().indexOf(' ') !== -1){
  406. info.innerText = title+'不能包含空格';
  407. } else {
  408. info.innerText = '';
  409. }
  410. input.style.borderColor = '#c3c3c3';
  411. }
  412. },
  413. button:{
  414. exit:function () {
  415. if ($("div[type='login']").is(event.target) || $("button[type='quit']").is(event.target)){
  416. $("div[type='login']").css('display','none');
  417. }
  418. },
  419. file:function () {
  420. let div_image = $(event.target);
  421. let input_file = $(event.target).parent('label').parent('div').prev('input');
  422. input_file.trigger('click').change(function(){
  423. if($(this).val().length > 0){
  424. var file_Reader = new FileReader();
  425. file_Reader.readAsDataURL(this.files[0]);
  426. // 获取成功
  427. file_Reader.onload = function(){
  428. sessionStorage.setItem('image',this.result);
  429. div_image.css({
  430. backgroundImage:'url('+this.result+')',
  431. outline:'none'
  432. }).find('i').css('display','none');
  433. }
  434. } else {
  435. div_image.css({
  436. backgroundImage: 'url()',
  437. outline: 'rgb(195, 195, 195) dotted 1px',
  438. }).find('i').css('display','block');
  439. }
  440. });
  441. },
  442. logon:function () {
  443. var message = $(event.target).parent('label').prevAll('label');
  444. var input_file = $(event.target).parent('label').parent('div').prev('input').val();
  445. var username = $(message[2]).find('input').val();
  446. var password = $(message[1]).find('input').val();
  447. var email = $(message[0]).find('input').val();
  448. var username_info = $(message[2]).next('span')[0];
  449. var password_info = $(message[1]).next('span')[0];
  450. var email_info = $(message[0]).next('span')[0];
  451. var username_title = $(message[2]).find('span').eq(1).text();
  452. var password_title = $(message[1]).find('span').eq(1).text();
  453. var email_title = $(message[0]).find('span').eq(1).text();
  454. if(
  455. $(event.target).parent('label').parent('div').prev('input').val() === defaultStatus
  456. ||
  457. $(event.target).parent('label').parent('div').prev('input').val() === null
  458. ) {
  459. $(message[3]).next('span')[0].innerText = '请设置头像'
  460. } else {
  461. $(message[3]).next('span')[0].innerText = ''
  462. }
  463. if (username === defaultStatus||username===null){
  464. username_info.innerText = username_title+'不能为空';
  465. } else if (username.indexOf(' ') !== -1){
  466. username_info.innerText = username_title+'不能包含空格';
  467. }
  468. if (password === defaultStatus||password ===null){
  469. password_info.innerText = password_title+'不能为空';
  470. } else if (password.indexOf(' ') !== -1){
  471. password_info.innerText = password_title+'不能包含空格';
  472. }
  473. if (email === defaultStatus||email ===null){
  474. email_info.innerText = email_title+'不能为空';
  475. } else if (email.indexOf(' ') !== -1){
  476. email_info.innerText = email_title+'不能包含空格';
  477. } else if (email.indexOf('@') === -1){
  478. email_info.innerText = email_title+'缺少必要@标识符';
  479. }
  480. if (
  481. input_file !== defaultStatus
  482. &&input_file !== null
  483. &&username !== defaultStatus
  484. &&username !== null
  485. &&username.indexOf(' ') === -1
  486. &&password !== defaultStatus
  487. &&password !== null
  488. &&password.indexOf(' ') === -1
  489. &&email !== defaultStatus
  490. &&email !== null
  491. &&email.indexOf(' ') === -1
  492. &&email.indexOf('@') !== -1){
  493. POST('logon',{
  494. image:sessionStorage.getItem('image'),
  495. account:username,
  496. password:password,
  497. email:email,
  498. },function (data) {
  499. console.log(data)
  500. alert_s(data.msg);
  501. if (data.error === 1){
  502. this.exit();
  503. }
  504. })
  505. }
  506. }
  507. }
  508. }
  509. };
  510. }
  511. });
  512. //启用组件
  513. new Vue({
  514. el:'#ifame'
  515. })
  516. })