Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

256 rader
6.3 KiB

  1. <template>
  2. <view class="page">
  3. <view class="content">
  4. <!-- 标题 -->
  5. <view class="main-title">欢迎注册力软框架 App 端体验账号!</view>
  6. <!-- 注册介绍 -->
  7. <view class="intro">
  8. <view class="intro-text">注册登录力软账号后,您将可以体验力软框架产品中的所有功能与业务</view>
  9. <view class="intro-tips">
  10. <l-icon type="sort" class="margin-right-sm" />
  11. 办公自动化
  12. </view>
  13. <view class="intro-tips">
  14. <l-icon type="shop" class="margin-right-sm" />
  15. 进销存管理
  16. </view>
  17. <view class="intro-tips">
  18. <l-icon type="form" class="margin-right-sm" />
  19. 自定义表单
  20. </view>
  21. <view class="intro-tips">
  22. <l-icon type="squarecheck" class="margin-right-sm" />
  23. 工作流审批
  24. </view>
  25. <view class="intro-tips">
  26. <l-icon type="rank" class="margin-right-sm" />
  27. 数据可视化
  28. </view>
  29. <view class="intro-tips">
  30. <l-icon type="news" class="margin-right-sm" />
  31. 电子公告板
  32. </view>
  33. </view>
  34. <!-- 提醒 -->
  35. <view class="signup-tips">
  36. 如果您之前已在力软框架 PC 端中注册过体验账号,可以直接使用原账号登录,无需另行注册
  37. </view>
  38. <!-- 账户密码表单 (v-if 防钉钉小程序报错) -->
  39. <l-input v-model="phone" placeholder="手机号码"><l-icon slot="title" type="mobile" /></l-input>
  40. <l-input v-if="sendCode || !sendOk" v-model="code" placeholder="请输入验证码" focus>
  41. <l-icon slot="title" type="lock" />
  42. </l-input>
  43. <!-- 获取验证码/完成注册的按钮 -->
  44. <l-button
  45. v-if="!sendCode"
  46. @click="getCode"
  47. :disabled="!sendOk"
  48. size="lg"
  49. line="blue"
  50. class="margin-top block"
  51. block
  52. >
  53. {{ sendOk ? '获取验证码' : `请${waitSec}秒后重发` }}
  54. </l-button>
  55. <l-button v-if="sendCode || !sendOk" @click="signUp" size="lg" color="green" class="margin-top block" block>
  56. 完成注册
  57. </l-button>
  58. <!-- 重发验证码的小按钮 -->
  59. <view class="margin-top text-center">
  60. <l-button v-if="sendCode" @click="getCode" :disabled="!sendOk" line="yellow">
  61. 重新发送验证码 {{ sendOk ? '' : `请${waitSec}秒后重发` }}
  62. </l-button>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import moment from 'moment'
  69. let nextTime = moment().subtract(1, 'second')
  70. export default {
  71. data() {
  72. return {
  73. phone: '',
  74. code: '',
  75. sendCode: false,
  76. sendOk: true,
  77. timer: null,
  78. waitSec: 0
  79. }
  80. },
  81. onShow() {
  82. // 按照当前和本地存储的下次发验证码的间隔时间中的更长的来计算
  83. const savedNextTime = this.GET_STORAGE('nextTime')
  84. if (savedNextTime && moment(savedNextTime).isSameOrAfter(nextTime)) {
  85. nextTime = moment(savedNextTime)
  86. this.sendCode = true
  87. }
  88. // 定时器;间隔时间达到,则允许再次发送验证码;间隔时间不够,则刷新倒计时秒数
  89. const setTime = () => {
  90. this.sendOk = moment(nextTime).isSameOrBefore()
  91. if (!this.sendOk) {
  92. this.waitSec = moment
  93. .duration(moment(nextTime).diff())
  94. .asSeconds()
  95. .toFixed(0)
  96. }
  97. }
  98. this.timer = setInterval(setTime, 1000)
  99. setTime()
  100. },
  101. onHide() {
  102. clearInterval(this.timer)
  103. },
  104. methods: {
  105. // 点击获取验证码按钮
  106. async getCode() {
  107. if (!this.checkInput() || !this.sendOk) {
  108. return
  109. }
  110. // 发送验证码
  111. const result = await this.HTTP_GET(
  112. 'https://www.learun.cn/webapi/securitycode',
  113. { mobileCode: this.phone, sourceUrl: '小程序注册' },
  114. '验证码发送失败'
  115. )
  116. if (!result) {
  117. return
  118. }
  119. this.sendOk = false
  120. // 设置90秒的发送间隔,存入 Store 本地存储
  121. const next = moment()
  122. .add(90, 'seconds')
  123. .format('YYYY-MM-DD HH:mm:ss')
  124. this.SET_STORAGE('nextTime', next)
  125. nextTime = next
  126. this.TOAST('验证码发送成功')
  127. this.sendCode = true
  128. },
  129. // 点击注册按钮
  130. async signUp() {
  131. this.LOADING('登录中…')
  132. // 根据不同的登录方式,调用 API
  133. const result = await this.HTTP_POST(
  134. '/user/login',
  135. { username: this.phone, password: this.MD5(this.code) },
  136. '登录失败'
  137. )
  138. if (!result) {
  139. return
  140. }
  141. // loginUser 中合并 role、post 两个字段
  142. const { baseinfo, mpinfo, post, role } = result
  143. const user = { ...baseinfo, post, role }
  144. const token = baseinfo.token
  145. // 返回的用户信息中,有 mpinfo 字段表示是否是小程序
  146. if (mpinfo && Array.isArray(mpinfo) && mpinfo.includes(type)) {
  147. user.miniProgram = true
  148. }
  149. this.SET_GLOBAL('token', token)
  150. this.SET_GLOBAL('loginUser', user)
  151. this.SET_STORAGE('token', token)
  152. this.HIDE_LOADING()
  153. this.TAB_TO('/pages/home')
  154. },
  155. // 验证输入
  156. checkInput() {
  157. if (!/^1\d{10}$/.test(this.phone)) {
  158. this.CONFIRM('手机号码错误', '请输入正确的手机号码,目前支持格式:1开头,共11位,不能包含区号和国家地区代码')
  159. return false
  160. }
  161. return true
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="less">
  167. page {
  168. height: 100%;
  169. }
  170. /* #ifdef MP-ALIPAY */
  171. .page {
  172. height: 100%;
  173. position: absolute;
  174. }
  175. /* #endif */
  176. </style>
  177. <style lang="less" scoped>
  178. .page {
  179. height: 100%;
  180. width: 100%;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. .content {
  185. text-align: center;
  186. width: 100%;
  187. padding: 0 38rpx;
  188. .signup-tips {
  189. color: #999;
  190. margin: 20rpx 0 40rpx;
  191. }
  192. .main-title {
  193. display: block;
  194. margin: 20rpx 0;
  195. color: #555;
  196. font-size: 1.4em;
  197. }
  198. .intro {
  199. margin: 20rpx 0;
  200. .intro-text {
  201. font-size: 1.1em;
  202. margin-bottom: 20rpx;
  203. }
  204. .intro-tips {
  205. display: inline-block;
  206. padding: 20rpx 30rpx;
  207. border-radius: 4px;
  208. background-color: #ffffff;
  209. margin: 10rpx 10rpx;
  210. border: solid 1px #555;
  211. box-shadow: #000000 1px 1px;
  212. }
  213. }
  214. }
  215. }
  216. </style>