index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view class="main">
  3. <view class="overlay">
  4. <view class="one">
  5. <uni-forms ref="baseForm" :rules="rules" :modelValue="form" label-width="80px">
  6. <uni-forms-item label="账号" required name="account">
  7. <uni-easyinput v-model="form.account" placeholder="请输入账号" />
  8. </uni-forms-item>
  9. <uni-forms-item label="密码" required name="password">
  10. <uni-easyinput type="password" v-model="form.password" placeholder="请输入密码" />
  11. </uni-forms-item>
  12. <uni-forms-item label="确认密码" required name="ispassword">
  13. <uni-easyinput type="password" v-model="form.ispassword" placeholder="请输入确认密码" />
  14. </uni-forms-item>
  15. <uni-forms-item label="昵称" required name="nick_name">
  16. <uni-easyinput v-model="form.nick_name" placeholder="请输入昵称" />
  17. </uni-forms-item>
  18. <uni-forms-item label="性别" required name="gender">
  19. <uni-data-checkbox v-model="form.gender" :localdata="genderList"
  20. :map="{text:'label',value:'value'}" />
  21. </uni-forms-item>
  22. <uni-forms-item label="所属产业" required name="industry">
  23. <uni-data-select v-model="form.industry" :localdata="industryList"
  24. @change="industryChange"></uni-data-select>
  25. </uni-forms-item>
  26. <uni-forms-item label="手机号" required name="phone">
  27. <uni-easyinput v-model="form.phone" placeholder="请输入手机号" />
  28. </uni-forms-item>
  29. <uni-forms-item label="电子邮箱">
  30. <uni-easyinput v-model="form.email" placeholder="请输入电子邮箱" />
  31. </uni-forms-item>
  32. </uni-forms>
  33. <button class="button_1" type="primary" @click="submit('baseForm')">注册</button>
  34. </view>
  35. <view class="two">
  36. <checkbox-group @change="changeAgree">
  37. <label>
  38. <checkbox color="#2979ff" :checked="agree" />
  39. <text @tap.stop="toAgree()">我已阅读并同意<text style="color: #2979ff;"
  40. @click="toAgree">《用户服务协议》</text>及
  41. <text style="color: #2979ff;" @click="toAgree">《隐私策略》</text>
  42. </text>
  43. </label>
  44. </checkbox-group>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. agree: false,
  54. openid: "",
  55. form: {
  56. openid: '',
  57. account: '',
  58. password: '',
  59. ispassword: '',
  60. nick_name: '',
  61. gender: '',
  62. industry: '',
  63. email: '',
  64. role: ['User']
  65. },
  66. // 校验规则
  67. rules: {
  68. account: {
  69. rules: [{
  70. required: true,
  71. errorMessage: '账号不能为空'
  72. }]
  73. },
  74. nick_name: {
  75. rules: [{
  76. required: true,
  77. errorMessage: '昵称不能为空'
  78. }]
  79. },
  80. gender: {
  81. rules: [{
  82. required: true,
  83. errorMessage: '性别不能为空'
  84. }]
  85. },
  86. industry: {
  87. rules: [{
  88. required: true,
  89. errorMessage: '所属产业不能为空'
  90. }]
  91. },
  92. password: {
  93. rules: [{
  94. required: true,
  95. errorMessage: '密码不能为空'
  96. }]
  97. },
  98. ispassword: {
  99. rules: [{
  100. required: true,
  101. errorMessage: '确认密码不能为空'
  102. },
  103. {
  104. validateFunction: function(rule, value, data, callback) {
  105. if (value != data.password) {
  106. callback('两次输入的密码必须相同')
  107. }
  108. return true
  109. }
  110. }
  111. ]
  112. },
  113. phone: {
  114. rules: [{
  115. required: true,
  116. errorMessage: '手机号不能为空'
  117. }]
  118. },
  119. },
  120. // 字典表
  121. genderList: [],
  122. industryList: [],
  123. }
  124. },
  125. onLoad: async function(e) {
  126. const that = this;
  127. // 查询平台信息
  128. await that.searchOpenids();
  129. await that.searchOther();
  130. },
  131. onReady() {
  132. // 需要在onReady中设置规则
  133. this.$refs.baseForm.setRules(this.rules)
  134. },
  135. methods: {
  136. async searchOpenids() {
  137. const that = this;
  138. uni.getStorage({
  139. key: 'openid',
  140. success: function(res) {
  141. that.$set(that, `openid`, res.data);
  142. },
  143. fail: function(err) {
  144. uni.login({
  145. success: async function(res) {
  146. if (res.code) {
  147. const aee = await that.$app('/wechat/api/login/app',
  148. 'GET', {
  149. js_code: res.code,
  150. config: that.$config.wx_projectkey
  151. })
  152. if (aee.errcode == '0') {
  153. uni.setStorage({
  154. key: "openid",
  155. data: aee.data.openid
  156. })
  157. that.$set(that, `openid`, aee.data.openid);
  158. } else {
  159. uni.showToast({
  160. title: aee.errmsg,
  161. icon: 'none'
  162. })
  163. }
  164. } else {
  165. uni.showToast({
  166. title: res.errMsg,
  167. icon: 'none'
  168. })
  169. }
  170. }
  171. });
  172. }
  173. })
  174. },
  175. async searchOther() {
  176. const that = this;
  177. let res;
  178. // 查询性别
  179. res = await that.$api(`/dictData`, 'GET', {
  180. code: 'gender',
  181. is_use: '0',
  182. })
  183. if (res.errcode == '0') that.$set(that, `genderList`, res.data);
  184. // 查询所属产业
  185. res = await that.$api(`/sector`, 'GET', {
  186. is_use: '0',
  187. })
  188. if (res.errcode == '0') {
  189. for (let val of res.data) {
  190. val.text = val.title
  191. val.value = val.id
  192. }
  193. that.$set(that, `industryList`, res.data);
  194. }
  195. },
  196. // 选择产业
  197. industryChange(e) {
  198. const that = this;
  199. let data = that.industryList.find(i => i.id == e);;
  200. if (data) {
  201. that.$set(that.form, `industry`, data.title)
  202. }
  203. },
  204. // 注册
  205. submit(ref) {
  206. const that = this;
  207. let agree = that.agree;
  208. let openid = that.openid;
  209. if (agree) {
  210. if (openid) {
  211. that.$refs[ref].validate().then(async res => {
  212. if (res.password == res.ispassword) {
  213. res.openid = openid
  214. const arr = await that.$api(`/user`, 'POST', res);
  215. if (arr.errcode == '0') {
  216. uni.showToast({
  217. title: '注册成功',
  218. icon: 'success'
  219. })
  220. uni.navigateBack({
  221. delta: 1
  222. })
  223. } else {
  224. uni.showToast({
  225. title: arr.errmsg,
  226. icon: 'none'
  227. })
  228. }
  229. } else {
  230. uni.showToast({
  231. title: `密码不一致`,
  232. icon: 'error'
  233. });
  234. }
  235. }).catch(err => {
  236. console.log('err', err);
  237. })
  238. } else {
  239. uni.showToast({
  240. title: '系统更新中,请稍后再试!',
  241. icon: 'none'
  242. })
  243. }
  244. } else {
  245. uni.showToast({
  246. title: '请阅读并同意用户协议和隐私政策',
  247. icon: 'none'
  248. })
  249. }
  250. },
  251. // 同意隐私协议
  252. changeAgree() {
  253. const that = this;
  254. that.$set(that, `agree`, !that.agree);
  255. },
  256. // 查看协议
  257. toAgree() {
  258. uni.navigateTo({
  259. url: '/pagesMy/agree/index'
  260. })
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss">
  266. .main {
  267. display: flex;
  268. flex-direction: column;
  269. box-sizing: border-box;
  270. width: 100vw;
  271. min-height: 100vh;
  272. position: relative;
  273. // background-image: url('../../static/loginbg.jpg');
  274. // background-repeat: no-repeat;
  275. // background-size: cover;
  276. // background-position: center;
  277. .overlay {
  278. position: absolute;
  279. top: 0;
  280. left: 0;
  281. right: 0;
  282. bottom: 0;
  283. background-color: rgba(255, 255, 255, 0.5);
  284. /* 白色半透明背景 */
  285. .one {
  286. padding: 2vw 5vw;
  287. .uni-select {
  288. background: #fff !important;
  289. }
  290. .button_1 {
  291. color: var(--mainColor);
  292. background: linear-gradient(90deg, #1E83FF, #1071e6);
  293. }
  294. }
  295. .two {
  296. padding: 5vw;
  297. text-align: center;
  298. font-size: var(--font12Size);
  299. }
  300. }
  301. }
  302. </style>