login.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. if (!Array) {
  4. const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
  5. const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
  6. const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
  7. const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  8. (_easycom_up_upload2 + _easycom_up_radio2 + _easycom_up_radio_group2 + _easycom_up_input2)();
  9. }
  10. const _easycom_up_upload = () => "../node-modules/uview-plus/components/u-upload/u-upload.js";
  11. const _easycom_up_radio = () => "../node-modules/uview-plus/components/u-radio/u-radio.js";
  12. const _easycom_up_radio_group = () => "../node-modules/uview-plus/components/u-radio-group/u-radio-group.js";
  13. const _easycom_up_input = () => "../node-modules/uview-plus/components/u-input/u-input.js";
  14. if (!Math) {
  15. (_easycom_up_upload + _easycom_up_radio + _easycom_up_radio_group + _easycom_up_input)();
  16. }
  17. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  18. __name: "login",
  19. emits: ["showChange"],
  20. setup(__props, { emit }) {
  21. const $api = common_vendor.inject("$api");
  22. const $apifile = common_vendor.inject("$apifile");
  23. const showType = common_vendor.ref(false);
  24. const form = common_vendor.ref({});
  25. const roleList = common_vendor.ref([]);
  26. const agree = common_vendor.ref(false);
  27. const openid = common_vendor.computed(() => {
  28. return common_vendor.index.getStorageSync("openid");
  29. });
  30. common_vendor.computed(() => {
  31. return common_vendor.index.getStorageSync("user");
  32. });
  33. const config = common_vendor.computed(() => {
  34. return common_vendor.index.getStorageSync("config");
  35. });
  36. common_vendor.onShow(async () => {
  37. await searchOther();
  38. });
  39. const searchOther = async () => {
  40. let res;
  41. res = await $api(`dictData`, "GET", { code: "role", is_use: "0" });
  42. if (res.errcode === 0)
  43. roleList.value = res.data;
  44. };
  45. const deletePic = (event) => {
  46. form.value.icon = [];
  47. };
  48. const afterRead = async (event) => {
  49. const url = event.file[0].url;
  50. const result = await $apifile(`/web/learn_user/upload`, "file", url, "file");
  51. if (result.errcode === 0)
  52. form.value.icon = [result];
  53. };
  54. const toCancel = async () => {
  55. form.value = { icon: [] };
  56. showType.value = false;
  57. agree.value = false;
  58. emit("showChange", false);
  59. };
  60. const isValidPhoneNumber = (phoneNumber) => {
  61. const regex = /^1[3456789]\d{9}$/;
  62. return regex.test(phoneNumber);
  63. };
  64. const toLogin = async () => {
  65. if (agree.value) {
  66. if (openid.value) {
  67. if (form.value.type) {
  68. if (form.value.phone) {
  69. if (isValidPhoneNumber(form.value.phone)) {
  70. common_vendor.index.getUserProfile({
  71. desc: "用于展示",
  72. success: async function(res) {
  73. const type = form.value.type;
  74. delete form.value.type;
  75. let parmas = {
  76. openid: openid.value,
  77. status: "1"
  78. };
  79. if (!form.value.nick_name)
  80. parmas.nick_name = res.userInfo.nickName + common_vendor.hooks().valueOf();
  81. if (!form.value.icon || form.value.icon.length === 0)
  82. parmas.icon = config.value.icon;
  83. let arr;
  84. if (type == "0")
  85. arr = await $api(`teacher`, "POST", { ...form.value, ...parmas, is_show: "1" });
  86. else
  87. arr = await $api(`student`, "POST", { ...form.value, ...parmas });
  88. if (arr.errcode == "0") {
  89. let role_type;
  90. if (type == "0")
  91. role_type = "Teacher";
  92. else
  93. role_type = "Student";
  94. common_vendor.index.setStorageSync("user", { ...arr.data, role_type });
  95. common_vendor.index.showToast({
  96. title: "登录成功",
  97. icon: "success"
  98. });
  99. await toCancel();
  100. } else {
  101. common_vendor.index.showToast({
  102. title: arr.errmsg,
  103. icon: "error"
  104. });
  105. }
  106. },
  107. fail: function(err) {
  108. console.log(err);
  109. }
  110. });
  111. } else {
  112. common_vendor.index.showToast({
  113. title: "请输入正确的手机号!",
  114. icon: "none"
  115. });
  116. }
  117. } else {
  118. common_vendor.index.showToast({
  119. title: "请输入手机号!",
  120. icon: "none"
  121. });
  122. }
  123. } else {
  124. common_vendor.index.showToast({
  125. title: "请选择用户身份!",
  126. icon: "none"
  127. });
  128. }
  129. } else {
  130. common_vendor.index.showToast({
  131. title: "系统更新中,请稍后再试!",
  132. icon: "none"
  133. });
  134. }
  135. } else {
  136. common_vendor.index.showToast({
  137. title: "请阅读并同意软件使用许可协议和隐私协议",
  138. icon: "none"
  139. });
  140. }
  141. };
  142. const toAgree = () => {
  143. common_vendor.index.navigateTo({
  144. url: `/pagesHome/agree/index`
  145. });
  146. };
  147. const changeAgree = () => {
  148. agree.value = !agree.value;
  149. };
  150. return (_ctx, _cache) => {
  151. return {
  152. a: common_vendor.t(common_vendor.unref(config).title || "学吧"),
  153. b: common_vendor.o(afterRead),
  154. c: common_vendor.o(deletePic),
  155. d: common_vendor.p({
  156. fileList: form.value.icon,
  157. name: "icon",
  158. multiple: true,
  159. maxCount: 1
  160. }),
  161. e: common_vendor.f(roleList.value, (item, index, i0) => {
  162. return {
  163. a: index,
  164. b: "b3197993-2-" + i0 + ",b3197993-1",
  165. c: common_vendor.p({
  166. customStyle: {
  167. marginRight: "16px"
  168. },
  169. label: item.label,
  170. name: item.value
  171. })
  172. };
  173. }),
  174. f: common_vendor.o(($event) => form.value.type = $event),
  175. g: common_vendor.p({
  176. placement: "row",
  177. modelValue: form.value.type
  178. }),
  179. h: common_vendor.o(($event) => form.value.nick_name = $event),
  180. i: common_vendor.p({
  181. placeholder: "请输入昵称",
  182. border: "surround",
  183. shape: "circle",
  184. modelValue: form.value.nick_name
  185. }),
  186. j: common_vendor.o(($event) => form.value.phone = $event),
  187. k: common_vendor.p({
  188. placeholder: "请输入手机号",
  189. border: "surround",
  190. shape: "circle",
  191. modelValue: form.value.phone
  192. }),
  193. l: agree.value,
  194. m: common_vendor.t(common_vendor.unref(config).title || "学吧"),
  195. n: common_vendor.o(($event) => toAgree()),
  196. o: common_vendor.o(changeAgree),
  197. p: common_vendor.o(toCancel),
  198. q: common_vendor.o(toLogin),
  199. r: common_vendor.o(() => {
  200. })
  201. };
  202. };
  203. }
  204. });
  205. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b3197993"], ["__file", "D:/project/学吧/learn_applet/components/login.vue"]]);
  206. wx.createComponent(Component);