index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <div class="wechat-view">
  3. <div class="header-view">
  4. <div class="hearder-kuang">
  5. <div class="header-img">
  6. <img src="/images/mobile/@2x/wechat/header-img.png" :src="headerImg"/>
  7. </div>
  8. </div>
  9. <div class="header-name">
  10. {{userName}}
  11. </div>
  12. <img src="/images/mobile/@2x/wechat/headerbg.png" class="headerbg"/>
  13. </div>
  14. <div class="middle-view">
  15. <ul>
  16. <li class="telphone">
  17. <input placeholder="请输入手机号" type="tel" maxlength="11" @blur="telphoneBlur" v-model="telphoneNum"/>
  18. </li>
  19. <li class="wechat-view-info">
  20. <div v-show="telerror">
  21. 请输入正确的手机号码
  22. </div>
  23. </li>
  24. <li class="password" v-if="!bindShow">
  25. <input placeholder="请输入密码" type="password" v-model="passwordNum"/>
  26. </li>
  27. <li v-if="bindShow" class="code clearfix">
  28. <input placeholder="请输入验证码" type="tel" v-model="codeNum" style="margin-left: 0;"/>
  29. <span class="pull-right codeBtn" @click="getCode()">
  30. {{showExtraTime ? getExtraTime + 'S' : '获取验证码'}}
  31. </span>
  32. </li>
  33. <li class="wechat-view-info clearfix" v-if="bindShow">
  34. <div v-show="codeerror" class="pull-left">
  35. 验证码错误
  36. </div>
  37. <div class="pull-right" @click="bindShow = false">用户名密码登录</div>
  38. </li>
  39. <li class="toInfoBind" @click="toInfoBind()" v-if="!bindShow">通过短信绑定</li>
  40. </ul>
  41. <div class="loginBtn" @click="login">确定绑定已有账号登录</div>
  42. <div class="register">还没有优软账号,直接<span @click="resgiter">创建新账号</span></div>
  43. <nuxt-link :to="'/'" class="mobile_footer company" tag="div">
  44. <div class="hr"></div>
  45. <img src="/images/mobile/@2x/wechat/logo.png" alt="">
  46. <div class="hr right"></div>
  47. <!--<p>此页面由深圳优软商城科技有限公司提供</p>-->
  48. <!--<nuxt-link :to="'/'">www.usoftmall.com</nuxt-link>-->
  49. <!-- <a href="https://www.usoftmall.com">www.usoftmall.com</a> -->
  50. </nuxt-link>
  51. </div>
  52. <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
  53. <div class="listAlert" ref="userContent" v-show="wechatInfo.enterprises && enuu === ''">
  54. <ul>
  55. <li v-for="(item, index) in wechatInfo.enterprises" @click="clickItem(item)">
  56. {{item.enName}}
  57. </li>
  58. <li @click="clickItem({uu: 0})">
  59. <a>个人账户</a>
  60. </li>
  61. </ul>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import { RemindBox } from '~components/mobile/common'
  67. import BScroll from 'better-scroll'
  68. export default {
  69. name: 'wechatView',
  70. layout: 'mobileNoHeader',
  71. // middleware: 'authenticated',
  72. data() {
  73. return {
  74. collectResult: '',
  75. timeoutCount: 0,
  76. telerror: false,
  77. telphoneNum: '',
  78. passwordNum: '',
  79. codeNum: '',
  80. bindShow: false, // 选择手机验证码绑定
  81. codeerror: false, // 显示验证码错误
  82. showExtraTime: false, // 倒计时
  83. getExtraTime: 60,
  84. enuu: ''
  85. }
  86. },
  87. mounted() {
  88. let info = localStorage.getItem('USOFTMALLWECHATINFO')
  89. if (this.$route.query.url) {
  90. localStorage.setItem('RETURNURL', this.$route.query.url || '')
  91. }
  92. if (this.$route.query.enuu) {
  93. this.enuu = this.$route.query.enuu
  94. }
  95. let ua = this.$store.state.option.userAgent.toLowerCase()
  96. if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && !this.$route.query.code && !info) {
  97. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com/mobile/wechat&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  98. } else if (info) {
  99. // 绑定过的用户一定存在openid
  100. info = JSON.parse(info)
  101. if (info.openid) {
  102. this.$store.dispatch('GerWechatInfo', {code: '', openId: info.openid}).then(res => {
  103. // 存在enuu
  104. if (this.enuu) {
  105. this.loginFromEnuu()
  106. }
  107. })
  108. } else {
  109. localStorage.removeItem('USOFTMALLWECHATINFO')
  110. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com/mobile/wechat&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  111. }
  112. } else {
  113. // 用户第一次进入公众号
  114. // this.$store.dispatch('GerWechatInfo', {code: '', openId: 'o2o8JwgMp9I8Es7yneC88JD7H2ts'}) // 测试用的数据
  115. this.$store.dispatch('GerWechatInfo', {code: this.$route.query.code})
  116. }
  117. this.$nextTick(() => {
  118. if (this.BScroll) {
  119. this.BScroll.refresh()
  120. } else {
  121. this.BScroll = new BScroll(this.$refs.userContent, {
  122. click: true
  123. })
  124. }
  125. })
  126. },
  127. methods: {
  128. // 路由带有enuu
  129. loginFromEnuu() {
  130. let _item = {}
  131. this.wechatInfo.enterprises.forEach((item) => {
  132. if (item.uu === parseInt(this.enuu)) {
  133. _item = item
  134. }
  135. })
  136. this.clickItem(_item)
  137. },
  138. // 选择账套登录
  139. clickItem(item) {
  140. let userAccount = this.baseUtils.deepCopy(this.$store.state.option.wechatInfo.data.userAccount)
  141. userAccount.spaceUU = item.uu
  142. this.$http.get('/newLogin/other', {params: userAccount}).then(res => {
  143. this.$store.dispatch('loadUserInfo').then(() => {
  144. let _url = localStorage.getItem('RETURNURL')
  145. let _uu = item.uu === 0 ? '' : item.uu
  146. this.$jsonp(`${process.env.ssoUrl}/sso/login/other?spaceUU=${_uu}&appId=mall&userUU=${userAccount.userUU}`, {timeout: 5000, name: 'successCallback'}, (err) => {
  147. console.log(err)
  148. })
  149. if (_url !== '') {
  150. localStorage.removeItem('RETURNURL')
  151. this.$router.replace(_url)
  152. } else if (this.$route.query.url && this.$route.query.url !== '') {
  153. this.$router.replace(this.$route.query.url)
  154. } else {
  155. this.goLastPage()
  156. }
  157. })
  158. })
  159. },
  160. // 手机号码失去焦点
  161. telphoneBlur() {
  162. if (this.telphoneNum === '') { return }
  163. this.telerror = false
  164. if (!/^1[3|5|7|8]\d{9}$/.test(this.telphoneNum)) {
  165. this.telerror = true
  166. }
  167. },
  168. // 绑定操作
  169. login() {
  170. let openid = this.$store.state.option.wechatInfo.data.openid
  171. if (this.telerror === true) {
  172. return false
  173. }
  174. if (!this.telphoneNum || this.telphoneNum === '') {
  175. this.collectResult = '手机号码不能为空'
  176. this.timeoutCount++
  177. return false
  178. }
  179. // 'o2o8JwgMp9I8Es7yneC88JD7H2ts'
  180. let _item = {
  181. userTel: this.telphoneNum,
  182. openId: openid
  183. }
  184. if (this.bindShow === true) {
  185. if (!this.codeNum || this.codeNum === '') {
  186. this.collectResult = '验证码不能为空'
  187. this.timeoutCount++
  188. return false
  189. }
  190. _item.code = this.codeNum
  191. } else {
  192. if (!this.passwordNum || this.passwordNum === '') {
  193. this.collectResult = '密码不能为空'
  194. this.timeoutCount++
  195. return false
  196. }
  197. _item.userPwd = this.passwordNum
  198. }
  199. this.$http.post('/wx/bindUser', _item).then(res => {
  200. if (res.data.success) {
  201. this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', res.data)
  202. localStorage.setItem('USOFTMALLWECHATINFO', JSON.stringify(res.data))
  203. } else {
  204. localStorage.removeItem('USOFTMALLWECHATINFO')
  205. this.collectResult = res.data.message || res.data.errMsg
  206. this.timeoutCount++
  207. }
  208. }, err => {
  209. localStorage.removeItem('USOFTMALLWECHATINFO')
  210. this.collectResult = err.response.data || '绑定失败'
  211. this.timeoutCount++
  212. })
  213. },
  214. resgiter() {
  215. this.$http.get('/register/page').then(response => {
  216. if (response.data) {
  217. window.location.href = response.data.content
  218. }
  219. })
  220. },
  221. // 选择短信绑定操作
  222. toInfoBind() {
  223. this.bindShow = true
  224. },
  225. getCode() {
  226. if (this.telerror) {
  227. return false
  228. }
  229. if (!this.telphoneNum || this.telphoneNum === '') {
  230. this.collectResult = '手机号码不能为空'
  231. this.timeoutCount++
  232. return false
  233. }
  234. if (this.showExtraTime) {
  235. this.collectResult = '获取验证码已发送,请查收'
  236. this.timeoutCount++
  237. return
  238. }
  239. // todo 这里走请求验证码接口
  240. this.$http.get(`/wx/sendSmsCode?mobile=${this.telphoneNum}`).then((data) => {
  241. if (data.data.success) {
  242. this.showExtraTime = true
  243. this.$timer = setInterval(() => {
  244. this.getExtraTime--
  245. if (this.getExtraTime === 0) {
  246. this.showExtraTime = false
  247. clearInterval(this.$timer)
  248. }
  249. }, 1000)
  250. } else {
  251. this.collectResult = data.data.errMsg
  252. this.timeoutCount++
  253. }
  254. }, err => {
  255. this.collectResult = err.response.data || '获取失败'
  256. this.timeoutCount++
  257. })
  258. }
  259. },
  260. components: {
  261. RemindBox
  262. },
  263. computed: {
  264. userName() {
  265. // return ''
  266. return this.wechatInfo.nickname
  267. },
  268. headerImg() {
  269. // return ''
  270. return this.wechatInfo.headimgurl || '/images/mobile/@2x/wechat/header-img.png'
  271. },
  272. wechatInfo() {
  273. return this.$store.state.option.wechatInfo.data
  274. }
  275. }
  276. }
  277. </script>
  278. <style scoped lang="scss">
  279. .wechat-view {
  280. position: fixed;
  281. z-index: 999;
  282. width: 100%;
  283. left: 0;
  284. right: 0;
  285. top: 0;
  286. bottom: 0;
  287. background: #fff;
  288. .header-view {
  289. background: #376ef3;
  290. height: 4.26rem;
  291. width: 100%;
  292. position: relative;
  293. padding-top: 0.56rem;
  294. .hearder-kuang {
  295. background: rgba(0, 0, 0, 0.18);
  296. width: 1.86rem;
  297. height: 1.86rem;
  298. border-radius: 50%;
  299. margin: 0 auto;
  300. overflow: hidden;
  301. position: relative;
  302. .header-img {
  303. background: #fff;
  304. width: 1.6rem;
  305. height: 1.6rem;
  306. border-radius: 50%;
  307. overflow: hidden;
  308. text-align: center;
  309. position: absolute;
  310. left: 50%;
  311. top: 50%;
  312. margin: -0.8rem 0 0 -0.8rem;
  313. img {
  314. width: 1.6rem;
  315. height: 1.6rem;
  316. border-radius: 50%;
  317. vertical-align: center;
  318. }
  319. }
  320. }
  321. .header-name {
  322. font-size: 0.3rem;
  323. color: #fff;
  324. text-align: center;
  325. margin-top: 0.24rem;
  326. }
  327. .headerbg {
  328. position: absolute;
  329. width: 100%;
  330. height: 0.88rem;
  331. bottom: 0px;
  332. left: 0px;
  333. }
  334. }
  335. .middle-view {
  336. padding: 0 0.71rem;
  337. margin-top: 0.56rem;
  338. ul li {
  339. padding-bottom: 0.1rem;
  340. min-height: 0.4rem;
  341. &.wechat-view-info {
  342. color: #3872f4;
  343. font-size: 0.24rem;
  344. margin-left: 0.64rem;
  345. margin-top: 0.2rem;
  346. margin-bottom: 0.2rem;
  347. }
  348. input {
  349. margin-left: 0.34rem;
  350. color: #aaa;
  351. font-size: 0.3rem;
  352. height: 0.5rem;
  353. line-height: 0.5rem;
  354. border: 0;
  355. display: inline-block;
  356. vertical-align: top;
  357. }
  358. &.telphone {
  359. border-bottom: 1px solid #eee;
  360. &::before {
  361. background: url('/images/mobile/@2x/wechat/tel_icon.png');
  362. content: ' ';
  363. width: 0.28rem;
  364. height: 0.5rem;
  365. display: inline-block;
  366. background-size: 100% 100%;
  367. vertical-align: top;
  368. }
  369. input {
  370. margin-left: 0.4rem;
  371. }
  372. }
  373. &.password {
  374. border-bottom: 1px solid #eee;
  375. &::before {
  376. background: url('/images/mobile/@2x/wechat/pass_icon.png');
  377. content: ' ';
  378. width: 0.34rem;
  379. height: 0.42rem;
  380. display: inline-block;
  381. background-size: 100% 100%;
  382. vertical-align: top;
  383. }
  384. }
  385. &.code {
  386. border-bottom: 1px solid #eee;
  387. }
  388. &.toInfoBind {
  389. color: #3872f4;
  390. font-size: 0.28rem;
  391. text-align: right;
  392. margin-top: 0.2rem;
  393. margin-bottom: 0.2rem;
  394. }
  395. .codeBtn {
  396. font-size: 0.28rem;
  397. color: #376ef3;
  398. width: 1.8rem;
  399. height: 0.5rem;
  400. line-height: 0.5rem;
  401. border-radius: 0.04rem;
  402. border: 1px solid #376ef3;
  403. text-align: center;
  404. }
  405. }
  406. .loginBtn {
  407. width: 5.8rem;
  408. height: 0.9rem;
  409. line-height: 0.9rem;
  410. text-align: center;
  411. font-size: 0.3rem;
  412. color: #fff;
  413. background: #376ef3;
  414. border-radius: 5px;
  415. margin: 1rem auto 0;
  416. }
  417. .register {
  418. width: 5.8rem;
  419. text-align: left;
  420. font-size: 0.24rem;
  421. color: #999;
  422. margin: 0.25rem auto 0;
  423. span {
  424. color: #0076ff;
  425. font-size: 0.24rem;
  426. text-align: center;
  427. border: 1px solid #0076ff;
  428. border-radius: 5px;
  429. height:0.44rem;
  430. width: 1.48rem;
  431. margin-left: 0.2rem;
  432. }
  433. }
  434. .company {
  435. margin-top: 1.51rem;
  436. position: relative;
  437. text-align: center;
  438. img {
  439. width: 1.78rem;
  440. height: 0.39rem;
  441. margin-top: 0.24rem;
  442. }
  443. p {
  444. font-size: 0.21rem;
  445. color: #aaa;
  446. margin: 0.13rem 0 0 0;
  447. }
  448. a {
  449. margin-top: 0.12rem;
  450. font-size: 0.18rem;
  451. color: #bbb;
  452. }
  453. .hr {
  454. width: 1.62rem;
  455. height: 0.02rem;
  456. background: #e3e3e3;
  457. position: absolute;
  458. left: 0.3rem;
  459. top: 0.45rem;
  460. &.right {
  461. right: 0.3rem;
  462. left: auto;
  463. }
  464. }
  465. }
  466. }
  467. .listAlert {
  468. position: fixed;
  469. top: 0;
  470. left: 0;
  471. right: 0;
  472. bottom: 0;
  473. background: #fff;
  474. padding: 0 0.2rem;
  475. overflow: hidden;
  476. z-index: 10000;
  477. li {
  478. line-height: 0.98rem;
  479. height: 0.98rem;
  480. border-bottom: 1px solid #dedede;
  481. }
  482. }
  483. }
  484. </style>