index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. validateFunction: function(rule, value, data, callback) {
  98. const reg =
  99. /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[._~!@#$^&*])[A-Za-z0-9._~!@#$^&*]{8,16}$/g
  100. if (!reg.test(value)) {
  101. callback('包含英文字母大小写、数字和特殊符号的 8-16 位组合')
  102. }
  103. return true
  104. }
  105. }]
  106. },
  107. ispassword: {
  108. rules: [{
  109. required: true,
  110. errorMessage: '确认密码不能为空'
  111. },
  112. {
  113. validateFunction: function(rule, value, data, callback) {
  114. if (value != data.password) {
  115. callback('两次输入的密码必须相同')
  116. }
  117. return true
  118. }
  119. }
  120. ]
  121. },
  122. phone: {
  123. rules: [{
  124. required: true,
  125. errorMessage: '手机号不能为空'
  126. }, {
  127. validateFunction: function(rule, value, data, callback) {
  128. const reg = /^1[3-9]\d{9}$/
  129. if (!reg.test(value)) {
  130. callback('请输入正确的手机号')
  131. }
  132. return true
  133. }
  134. }]
  135. },
  136. },
  137. // 字典表
  138. genderList: [],
  139. industryList: [],
  140. }
  141. },
  142. onLoad: async function(e) {
  143. const that = this;
  144. // 查询平台信息
  145. await that.searchOpenids();
  146. await that.searchOther();
  147. },
  148. onReady() {
  149. // 需要在onReady中设置规则
  150. this.$refs.baseForm.setRules(this.rules)
  151. },
  152. methods: {
  153. async searchOpenids() {
  154. const that = this;
  155. uni.getStorage({
  156. key: 'openid',
  157. success: function(res) {
  158. that.$set(that, `openid`, res.data);
  159. },
  160. fail: function(err) {
  161. uni.login({
  162. success: async function(res) {
  163. if (res.code) {
  164. const aee = await that.$app('/wechat/api/login/app',
  165. 'GET', {
  166. js_code: res.code,
  167. config: that.$config.wx_projectkey
  168. })
  169. if (aee.errcode == '0') {
  170. uni.setStorage({
  171. key: "openid",
  172. data: aee.data.openid
  173. })
  174. that.$set(that, `openid`, aee.data.openid);
  175. } else {
  176. uni.showToast({
  177. title: aee.errmsg,
  178. icon: 'none'
  179. })
  180. }
  181. } else {
  182. uni.showToast({
  183. title: res.errMsg,
  184. icon: 'none'
  185. })
  186. }
  187. }
  188. });
  189. }
  190. })
  191. },
  192. async searchOther() {
  193. const that = this;
  194. let res;
  195. // 查询性别
  196. res = await that.$api(`/dictData`, 'GET', {
  197. code: 'gender',
  198. is_use: '0',
  199. })
  200. if (res.errcode == '0') that.$set(that, `genderList`, res.data);
  201. // 查询所属产业
  202. res = await that.$api(`/sector`, 'GET', {
  203. is_use: '0',
  204. })
  205. if (res.errcode == '0') {
  206. for (let val of res.data) {
  207. val.text = val.title
  208. val.value = val.id
  209. }
  210. that.$set(that, `industryList`, res.data);
  211. }
  212. },
  213. // 选择产业
  214. industryChange(e) {
  215. const that = this;
  216. let data = that.industryList.find(i => i.id == e);;
  217. if (data) {
  218. that.$set(that.form, `industry`, data.title)
  219. }
  220. },
  221. // 注册
  222. submit(ref) {
  223. const that = this;
  224. let agree = that.agree;
  225. let openid = that.openid;
  226. if (agree) {
  227. if (openid) {
  228. that.$refs[ref].validate().then(async res => {
  229. if (res.password == res.ispassword) {
  230. res.openid = openid
  231. const arr = await that.$api(`/user`, 'POST', res);
  232. if (arr.errcode == '0') {
  233. uni.showToast({
  234. title: '注册成功',
  235. icon: 'success'
  236. })
  237. uni.navigateBack({
  238. delta: 1
  239. })
  240. } else {
  241. uni.showToast({
  242. title: arr.errmsg,
  243. icon: 'none'
  244. })
  245. }
  246. } else {
  247. uni.showToast({
  248. title: `密码不一致`,
  249. icon: 'error'
  250. });
  251. }
  252. }).catch(err => {
  253. console.log('err', err);
  254. })
  255. } else {
  256. uni.showToast({
  257. title: '系统更新中,请稍后再试!',
  258. icon: 'none'
  259. })
  260. }
  261. } else {
  262. uni.showToast({
  263. title: '请阅读并同意用户协议和隐私政策',
  264. icon: 'none'
  265. })
  266. }
  267. },
  268. // 同意隐私协议
  269. changeAgree() {
  270. const that = this;
  271. that.$set(that, `agree`, !that.agree);
  272. },
  273. // 查看协议
  274. toAgree() {
  275. uni.navigateTo({
  276. url: '/pagesMy/agree/index'
  277. })
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="scss">
  283. .main {
  284. display: flex;
  285. flex-direction: column;
  286. box-sizing: border-box;
  287. width: 100vw;
  288. min-height: 100vh;
  289. position: relative;
  290. // background-image: url('../../static/loginbg.jpg');
  291. // background-repeat: no-repeat;
  292. // background-size: cover;
  293. // background-position: center;
  294. .overlay {
  295. position: absolute;
  296. top: 0;
  297. left: 0;
  298. right: 0;
  299. bottom: 0;
  300. background-color: rgba(255, 255, 255, 0.5);
  301. /* 白色半透明背景 */
  302. .one {
  303. padding: 2vw 5vw;
  304. .uni-select {
  305. background: #fff !important;
  306. }
  307. .button_1 {
  308. color: var(--mainColor);
  309. background: linear-gradient(90deg, #1E83FF, #1071e6);
  310. }
  311. }
  312. .two {
  313. padding: 5vw;
  314. text-align: center;
  315. font-size: var(--font12Size);
  316. }
  317. }
  318. }
  319. </style>