vue-module.js 30 KB

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