login.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 errors = common_vendor.ref({});
  28. const openid = common_vendor.computed(() => {
  29. return common_vendor.index.getStorageSync("openid");
  30. });
  31. const user = common_vendor.computed(() => {
  32. return common_vendor.index.getStorageSync("user");
  33. });
  34. const config = common_vendor.computed(() => {
  35. return common_vendor.index.getStorageSync("config");
  36. });
  37. common_vendor.onShow(async () => {
  38. if (!user.value)
  39. await searchOther();
  40. });
  41. const searchOther = async () => {
  42. let res;
  43. res = await $api(`dictData`, "GET", { code: "role", is_use: "0" });
  44. if (res.errcode === 0)
  45. roleList.value = res.data;
  46. };
  47. const deletePic = (event) => {
  48. form.value.icon = [];
  49. };
  50. const afterRead = async (event) => {
  51. const url = event.file[0].url;
  52. const result = await $apifile(`/web/learn_user/upload`, "file", url, "file");
  53. if (result.errcode === 0)
  54. form.value.icon = [result];
  55. };
  56. const toCancel = async () => {
  57. form.value = { icon: [] };
  58. showType.value = false;
  59. agree.value = false;
  60. emit("showChange", false);
  61. };
  62. const validateObject = (obj) => {
  63. const errors2 = {};
  64. if (!obj.type || obj.type.trim() === "") {
  65. errors2.type = "请选择身份类型!";
  66. }
  67. if (!obj.nick_name || obj.nick_name.trim() === "") {
  68. errors2.nick_name = "请填写昵称!";
  69. }
  70. if (!obj.phone || obj.phone.trim() === "") {
  71. errors2.phone = "请填写手机号!";
  72. } else {
  73. const regex = /^1[3456789]\d{9}$/;
  74. if (!regex.test(obj.phone))
  75. errors2.phone = "请填写正确的手机号码!";
  76. }
  77. if (Object.keys(errors2).length > 0) {
  78. return errors2;
  79. }
  80. return null;
  81. };
  82. const toLogin = async () => {
  83. if (agree.value) {
  84. if (openid.value) {
  85. const errorsInfo = await validateObject(form.value);
  86. if (errorsInfo) {
  87. errors.value = errorsInfo;
  88. for (const key in errorsInfo) {
  89. if (errorsInfo.hasOwnProperty(key)) {
  90. console.error(`${key} 错误: ${errorsInfo[key]}`);
  91. }
  92. }
  93. } else {
  94. common_vendor.index.getUserProfile({
  95. desc: "用于展示",
  96. success: async function(res) {
  97. const type = form.value.type;
  98. delete form.value.type;
  99. let parmas = {
  100. openid: openid.value,
  101. status: "1"
  102. };
  103. if (!form.value.nick_name)
  104. parmas.nick_name = res.userInfo.nickName + common_vendor.hooks().valueOf();
  105. if (!form.value.icon || form.value.icon.length === 0)
  106. parmas.icon = config.value.icon;
  107. let arr;
  108. if (type == "0")
  109. arr = await $api(`teacher`, "POST", { ...form.value, ...parmas, is_show: "1" });
  110. else
  111. arr = await $api(`student`, "POST", { ...form.value, ...parmas });
  112. if (arr.errcode == "0") {
  113. let role_type;
  114. if (type == "0")
  115. role_type = "Teacher";
  116. else
  117. role_type = "Student";
  118. common_vendor.index.setStorageSync("user", { ...arr.data, role_type });
  119. common_vendor.index.showToast({
  120. title: "登录成功",
  121. icon: "success"
  122. });
  123. await toCancel();
  124. } else {
  125. common_vendor.index.showToast({
  126. title: arr.errmsg,
  127. icon: "error"
  128. });
  129. }
  130. },
  131. fail: function(err) {
  132. console.log(err);
  133. }
  134. });
  135. }
  136. } else {
  137. common_vendor.index.showToast({
  138. title: "系统更新中,请稍后再试!",
  139. icon: "none"
  140. });
  141. }
  142. } else {
  143. common_vendor.index.showToast({
  144. title: "请阅读并同意软件使用许可协议和隐私协议",
  145. icon: "none"
  146. });
  147. }
  148. };
  149. const toAgree = () => {
  150. common_vendor.index.navigateTo({
  151. url: `/pagesHome/agree/index`
  152. });
  153. };
  154. const changeAgree = () => {
  155. agree.value = !agree.value;
  156. };
  157. return (_ctx, _cache) => {
  158. return common_vendor.e({
  159. a: common_vendor.t(common_vendor.unref(config).title || "学吧"),
  160. b: common_vendor.o(afterRead),
  161. c: common_vendor.o(deletePic),
  162. d: common_vendor.p({
  163. fileList: form.value.icon,
  164. name: "icon",
  165. multiple: true,
  166. maxCount: 1
  167. }),
  168. e: common_vendor.f(roleList.value, (item, index, i0) => {
  169. return {
  170. a: index,
  171. b: "b3197993-2-" + i0 + ",b3197993-1",
  172. c: common_vendor.p({
  173. customStyle: {
  174. marginRight: "16px"
  175. },
  176. label: item.label,
  177. name: item.value
  178. })
  179. };
  180. }),
  181. f: common_vendor.o(($event) => form.value.type = $event),
  182. g: common_vendor.p({
  183. placement: "row",
  184. modelValue: form.value.type
  185. }),
  186. h: errors.value.type
  187. }, errors.value.type ? {
  188. i: common_vendor.t(errors.value.type)
  189. } : {}, {
  190. j: common_vendor.o(($event) => form.value.nick_name = $event),
  191. k: common_vendor.p({
  192. placeholder: "请输入昵称",
  193. border: "surround",
  194. shape: "circle",
  195. modelValue: form.value.nick_name
  196. }),
  197. l: errors.value.nick_name
  198. }, errors.value.nick_name ? {
  199. m: common_vendor.t(errors.value.nick_name)
  200. } : {}, {
  201. n: common_vendor.o(($event) => form.value.phone = $event),
  202. o: common_vendor.p({
  203. placeholder: "请输入手机号",
  204. border: "surround",
  205. shape: "circle",
  206. modelValue: form.value.phone
  207. }),
  208. p: errors.value.phone
  209. }, errors.value.phone ? {
  210. q: common_vendor.t(errors.value.phone)
  211. } : {}, {
  212. r: agree.value,
  213. s: common_vendor.t(common_vendor.unref(config).title || "学吧"),
  214. t: common_vendor.o(($event) => toAgree()),
  215. v: common_vendor.o(changeAgree),
  216. w: common_vendor.o(toCancel),
  217. x: common_vendor.o(toLogin),
  218. y: common_vendor.o(() => {
  219. })
  220. });
  221. };
  222. }
  223. });
  224. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b3197993"], ["__file", "D:/project/学吧/learn_applet/components/login.vue"]]);
  225. wx.createComponent(Component);