| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- export default {
- state: {
- mid: 0,
- name: "未登录",
- showName: "未登录",
- phone: "",
- isLogin: false,
- guideStep: 0,
- registerInfo: null,
- },
- actions: ({ model, setState }) => ({
- updateUser({ ...userInfo }) {
- setState({ ...userInfo });
- },
- decrement() {
- const { count } = model();
- setState({ count: count - 1 });
- },
- getUserInfo() {
- const { updateUser } = model();
- const { httpGet } = model("httpModel");
- return httpGet("/merchant/my").then((res) => {
- if (res) {
- updateUser(res);
- }
- });
- },
- checkLogin() {
- const { getUserInfo, id, aliAccount } = model();
- const { getAsyncStorage } = model("httpModel");
- return new Promise((resolve) => {
- getUserInfo()
- .then(async (_) => {
- let guideStep = await getAsyncStorage("guideStep");
- if (status == "PASS") {
- guideStep = 4;
- }
- console.log(guideStep);
- if (guideStep) {
- setState({ guideStep: guideStep, isLogin: true });
- } else {
- setState({ isLogin: true });
- }
- resolve();
- })
- .catch((_) => {
- setState({ isLogin: false });
- resolve();
- });
- });
- },
- loginByPassword(phone, password) {
- const { httpPost, addAsyncStorage } = model("httpModel");
- const { checkLogin } = model();
- const { loading, success } = model("loadingModel");
- httpPost("/auth/loginByRegister", {
- phone: phone,
- password: password,
- })
- .then((res) => {
- addAsyncStorage("token", res);
- if (res) {
- success("登录成功");
- checkLogin();
- }
- })
- .catch((e) => {
- console.log(e);
- });
- },
- loginByCode(phone, code) {
- loading();
- httpPost("/auth/phoneLogin", {
- phone: phone,
- code: code,
- })
- .then((res) => {
- if (res) {
- updateUser(res);
- }
- })
- .catch((e) => {
- console.log(e);
- });
- },
- registerFirst({ ...data }) {
- setState({ registerInfo: data });
- const { pushRouter } = model("routersModel");
- pushRouter("RegisterSe");
- },
- registerUser({ ...data }) {
- const { checkLogin } = model();
- const { loading, success } = model("loadingModel");
- const { httpPost, addAsyncStorage } = model("httpModel");
- httpPost("/auth/merchantRegister", data).then((res) => {
- addAsyncStorage("token", res);
- if (res) {
- checkLogin();
- }
- });
- // setTimeout(() => {
- // success("注册成功");
- // }, 1000);
- // getUserInfo().then(_=>{
- // })
- },
- registerSecend({ ...data }) {
- const { registerInfo, registerUser } = model();
- let _registerInfo = {
- ...registerInfo,
- ...data,
- };
- registerUser(_registerInfo);
- },
- changeGuideStep(step, next) {
- const { addAsyncStorage } = model("httpModel");
- addAsyncStorage("guideStep", step);
- if (step == "finish") {
- setState({
- guideStep: "finish",
- });
- } else {
- const { replaceRouter, resetRouter } = model("routersModel");
- replaceRouter(next);
- }
- },
- saveMerchant({ ...data }) {
- const { mid, changeGuideStep } = model();
- const { loading, success } = model("loadingModel");
- const { httpPost, addAsyncStorage } = model("httpModel");
- httpPost(
- "/merchant/saveDTO",
- {
- ...data,
- mid: mid,
- },
- { body: "json" }
- ).then((res) => {
- changeGuideStep(3, "Guide4");
- });
- },
- checkInfo({ aliAccountEvent, aliNameEvent }) {
- const { aliAccount, aliName } = model();
- aliAccountEvent(aliAccount);
- aliNameEvent(aliName);
- },
- updateMerchant({ ...data }) {
- const { mid, getUserInfo } = model();
- const { loading, success } = model("loadingModel");
- const { httpPost, addAsyncStorage } = model("httpModel");
- return httpPost(
- "/merchant/saveDTO",
- {
- ...data,
- mid: mid,
- },
- { body: "json" }
- ).then((res) => {
- success("修改成功");
- if (res) {
- getUserInfo(res);
- }
- });
- },
- uploadStoreImg(img, type) {
- const { updateMerchant } = model();
- if (type == "banner") {
- return updateMerchant({ banner: img });
- } else {
- return updateMerchant({ logo: img });
- }
- },
- }),
- };
|