index2.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="container">
  3. <!-- 标题 -->
  4. <view class="title">
  5. <text>获取昵称头像</text>
  6. <text>未选择头像则为默认头像</text>
  7. </view>
  8. <!-- 选择头像 -->
  9. <view class="choose-avatar-row">
  10. <button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  11. <image class="avatar" :src="avatarUrl"></image>
  12. </button>
  13. <text>点击选择头像</text>
  14. </view>
  15. <!-- 选择昵称 -->
  16. <view class="choose-nickname-row">
  17. <text>昵称</text>
  18. <input v-model="nickName" @input="inputName" type="nickname" placeholder="请输入昵称" />
  19. </view>
  20. <!-- 选择电话 -->
  21. <view class="choose-nickname-row" style="border: 0;">
  22. <button class="avatar-wrapper" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
  23. style="width: 100%;">
  24. <text style="width: 100%;">点击授权获取手机号</text>
  25. </button>
  26. </view>
  27. <view v-if="isPhone" style="text-align: center;">
  28. <text>已获取手机号</text>
  29. </view>
  30. <!-- 按钮 -->
  31. <view class="login-row">
  32. <button @click="submit">登录</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. // import {
  38. // get,
  39. // post
  40. // } from '@/utils/request.js'
  41. // import localStorage from '@/utils/localStorage.js'
  42. export default {
  43. data() {
  44. return {
  45. avatarUrl: '',
  46. nickName: '',
  47. PhoneCode: '',
  48. imgUrl: '',
  49. isPhone: false
  50. }
  51. },
  52. mounted() {
  53. uni.showToast({
  54. title: '未登录请先注册',
  55. icon: 'none'
  56. })
  57. },
  58. methods: {
  59. getPhoneNumber(e) {
  60. this.PhoneCode = e.detail.code
  61. console.log(e.detail.code)
  62. this.isPhone = true
  63. },
  64. onChooseAvatar(e) {
  65. this.avatarUrl = e.detail.avatarUrl
  66. this.upImg(this.avatarUrl)
  67. },
  68. inputName(e) {
  69. this.nickName = e.detail.value
  70. },
  71. upImg(file) {
  72. let _this = this
  73. uni.uploadFile({
  74. url: 'http://xxxxxx:xxxx/lgb/upload/upload', // 上传的 URL 地址
  75. filePath: file, // 要上传的图片本地路径
  76. name: 'file', // 上传图片时使用的字段名
  77. header: { // 自定义请求头
  78. 'Content-Type': 'multipart/form-data'
  79. },
  80. formData: {
  81. 'fileType': 'images',
  82. 'dirName': 'cert'
  83. },
  84. success: function(uploadRes) {
  85. let result = JSON.parse(uploadRes.data)
  86. localStorage.set('imgUrl', result.data.fileUrl)
  87. console.log(this.imgUrl)
  88. },
  89. fail: function(err) {
  90. console.log('upload failed:', err)
  91. }
  92. })
  93. },
  94. async submit() {
  95. if (!this.nickName || !this.PhoneCode || !localStorage.get('imgUrl')) {
  96. uni.showToast({
  97. title: '请将数据填写完整',
  98. icon: 'none'
  99. })
  100. return
  101. }
  102. let result = await post('/lgb/user/register', {
  103. openId: localStorage.get('openid'),
  104. job: 0,
  105. name: this.nickName,
  106. code: this.PhoneCode,
  107. avatar: localStorage.get('imgUrl')
  108. }, {});
  109. setTimeout(() => {
  110. uni.showToast({
  111. title: '注册成功',
  112. icon: 'none'
  113. })
  114. }, 800)
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. view {
  121. box-sizing: border-box;
  122. }
  123. .container {
  124. width: 100%;
  125. height: 100%;
  126. position: absolute;
  127. left: 0;
  128. bottom: 0;
  129. padding: 0 20px;
  130. box-sizing: border-box;
  131. display: flex;
  132. flex-direction: column;
  133. background-color: #fff;
  134. border-top-left-radius: 10px;
  135. border-top-right-radius: 10px;
  136. .title {
  137. width: 100%;
  138. height: 12%;
  139. font-size: 20px;
  140. font-weight: bold;
  141. padding-top: 20px;
  142. text:nth-child(2) {
  143. display: block;
  144. font-size: 14px;
  145. font-weight: normal;
  146. margin-top: 5px;
  147. }
  148. }
  149. .choose-avatar-row,
  150. .choose-nickname-row {
  151. width: 100%;
  152. height: 9%;
  153. display: flex;
  154. justify-content: flex-start;
  155. align-items: center;
  156. padding: 10px 2px;
  157. font-size: 14px;
  158. border-top: 1px solid #ccc;
  159. border-bottom: 1px solid #ccc;
  160. .avatar-wrapper {
  161. width: 40px;
  162. height: 40px;
  163. margin: 0;
  164. padding: 0;
  165. margin-right: 10px;
  166. .avatar {
  167. width: 100%;
  168. height: 100%;
  169. }
  170. }
  171. }
  172. .choose-nickname-row {
  173. border-top: none;
  174. text {
  175. width: 45px;
  176. margin-right: 10px;
  177. }
  178. }
  179. .login-row {
  180. width: 100%;
  181. height: 30%;
  182. padding-top: 20px;
  183. display: flex;
  184. button {
  185. font-size: 14px;
  186. width: 30%;
  187. height: 40px;
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. border-color: transparent;
  192. color: #07c160;
  193. }
  194. .inactive {
  195. color: #ccc;
  196. }
  197. }
  198. }
  199. </style>