123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <view class="container">
- <view class="example">
- <uni-forms ref="form" :model="user" labelWidth="80px">
- <uni-forms-item label="用户昵称" name="nickName">
- <uni-easyinput v-model="user.nickName" placeholder="请输入昵称" />
- </uni-forms-item>
- <uni-forms-item label="手机号码" name="phonenumber">
- <uni-easyinput v-model="user.phonenumber" placeholder="请输入手机号码" />
- </uni-forms-item>
- <uni-forms-item label="邮箱" name="email">
- <uni-easyinput v-model="user.email" placeholder="请输入邮箱" />
- </uni-forms-item>
- <uni-forms-item label="性别" name="sex" required>
- <uni-data-checkbox v-model="user.sex" :localdata="sexs" />
- </uni-forms-item>
- </uni-forms>
- <button type="primary" @click="submit">提交</button>
- </view>
- </view>
- </template>
- <script setup>
- import { getUserProfile } from "@/api/system/user";
- import { updateUserProfile } from "@/api/system/user";
- import { onReady, onLoad, onShow, onNavigationBarButtonTap } from "@dcloudio/uni-app";
- import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance, toRefs } from "vue";
- const data = reactive({
- user: {
- nickName: "",
- phonenumber: "",
- email: "",
- sex: "",
- },
- sexs: [
- {
- text: "男",
- value: "0",
- },
- {
- text: "女",
- value: "1",
- },
- ],
- rules: {
- nickName: {
- rules: [
- {
- required: true,
- errorMessage: "用户昵称不能为空",
- },
- ],
- },
- phonenumber: {
- rules: [
- {
- required: true,
- errorMessage: "手机号码不能为空",
- },
- {
- pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
- errorMessage: "请输入正确的手机号码",
- },
- ],
- },
- email: {
- rules: [
- {
- required: true,
- errorMessage: "邮箱地址不能为空",
- },
- {
- format: "email",
- errorMessage: "请输入正确的邮箱地址",
- },
- ],
- },
- },
- });
- const { user, sexs, rules } = toRefs(data);
- const { proxy } = getCurrentInstance();
- const form = ref(null);
- function getUser() {
- getUserProfile().then((response) => {
- console.log(response);
- user.value = response.data.user;
- });
- }
- function submit(ref) {
- form.value.validate().then((res) => {
- updateUserProfile(user.value).then((response) => {
- proxy.$modal.msgSuccess("修改成功,重新登录后生效!");
- proxy.$tab.reLaunch("pages/mine/index");
- });
- });
- }
- onLoad((options) => {
- getUser();
- });
- onReady(() => {
- form.value.setRules(rules.value);
- });
- </script>
- <style>
- page {
- background-color: #ffffff;
- }
- </style>
- <style lang="scss">
- .example {
- padding: 15px;
- background-color: #fff;
- }
- .segmented-control {
- margin-bottom: 15px;
- }
- .button-group {
- margin-top: 15px;
- display: flex;
- justify-content: space-around;
- }
- .form-item {
- display: flex;
- align-items: center;
- flex: 1;
- }
- .button {
- display: flex;
- align-items: center;
- height: 35px;
- line-height: 35px;
- margin-left: 10px;
- }
- </style>
|