index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="content">
  3. <u-navbar
  4. title="南华禅寺灯会云游"
  5. @rightClick="rightClick"
  6. :autoBack="true" >
  7. </u-navbar>
  8. <div class="avatarUrl">
  9. <button class="but" type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseavatar">
  10. <img :src="userInfo.avatarUrl" class="refreshIcon"></img>
  11. </button>
  12. </div>
  13. <div class="userName">
  14. <text>昵称:</text>
  15. <input style=" text-align: left;width: 100px" :clearable="false" type="nickname" class="weui-input" :value="userInfo.nickName" @blur="bindblur"
  16. placeholder="请输入昵称" @input="bindinput" />
  17. </div> <view class="fixed bottom-48 w-full text-center">
  18. <view class="absolute" style="left: calc(50% - 112px);bottom: 100px">
  19. <u--image src="https://4dscene.4dage.com/new4dkk/deng/static/img/btn_enter@2x.png" width="224px" height="55px"></u--image>
  20. </view>
  21. <view class="butText text-center" @click="handleHome">退出登录</view>
  22. </view>
  23. <tabbar ref="tabbar" />
  24. </div>
  25. </template>
  26. <script>
  27. // import uButton from "uview-ui/components/u-button/u-button.vue";
  28. import tabbar from "components/tabbar/index.vue";
  29. import { userInfo, updateWxUser, logout } from "@/common/api.js";
  30. // import uNavbar from "uview-ui/components/u-navbar/u-navbar.vue";
  31. import { mapState } from "vuex";
  32. export default {
  33. components: {
  34. tabbar,
  35. // uButton
  36. // uNavbar
  37. },
  38. data() {
  39. return {
  40. title: "Hello World",
  41. avatarUrl: "",
  42. userName: "",
  43. show: false,
  44. };
  45. },
  46. computed: {
  47. ...mapState(["userInfo"]),
  48. },
  49. onLoad(e) {
  50. console.log(e, "onChooseAvatar");
  51. let that = this;
  52. this.$store.commit("changeUseinf", userInfo);
  53. userInfo({}).then((res) => {
  54. // uni.$u.toast("登录成功");
  55. // state.token = res.token;
  56. });
  57. if (e.scanCode) {
  58. //进入扫码
  59. that.$refs.tabbar.handleItem({name: "扫码打卡"}, 4)
  60. // uni.scanCode({
  61. // onlyFromCamera: true,
  62. // success: function (res) {
  63. // console.log("条码类型:" + res.scanType);
  64. // console.log("条码内容:" + res.result, that.$refs.tabbar);
  65. // that.$refs.tabbar.show = true;
  66. // // that.$store.commit("changeActive", index);
  67. // },
  68. // fail: function (e) {
  69. // console.log("扫码失败", e, that.$refs.tabbar.show);
  70. // // this.$store.commit("changeActive", 4);
  71. // that.$refs.tabbar.show = true;
  72. // },
  73. // });
  74. }
  75. },
  76. // // 在小程序的JS文件中定义接口
  77. // wx.miniProgram.onMessageToH5 = function (event) {
  78. // console.log('收到来自H5页面的消息:', event.data);
  79. // // 在这里处理接收到的消息
  80. // },
  81. methods: {
  82. onChooseavatar(e) {
  83. console.log(e, "onChooseAvatar");
  84. this.avatarUrl = e.detail.avatarUrl;
  85. this.upload_file(e.detail.avatarUrl);
  86. },
  87. upload_file(e) {
  88. wx.showLoading({
  89. title: "上传中",
  90. });
  91. let self = this;
  92. wx.uploadFile({
  93. url: "https://sit-nanhuacs.4dage.com/api/wx/upload",
  94. filePath: e, //图片路径
  95. name: "file",
  96. header: {
  97. "Content-Type": "multipart/form-data",
  98. token: uni.getStorageSync("token"),
  99. },
  100. formData: {
  101. type: "img",
  102. },
  103. success: function (a) {
  104. let res = a.data;
  105. res = JSON.parse(res);
  106. console.log(res, "data");
  107. if (res.code == 0) {
  108. const { data } = res;
  109. let avatarUrl = 'https://sit-nanhuacs.4dage.com' + data.filePath;
  110. self.avatar = 'https://sit-nanhuacs.4dage.com' + data.filePath;
  111. self.cdnUrl = 'https://sit-nanhuacs.4dage.com' + data.filePath;
  112. updateWxUser({ ...self.userInfo, avatarUrl: avatarUrl }).then((res) => {
  113. console.log(res);
  114. self.$store.commit("changeUseinf", userInfo);
  115. // if (res.code == 0) {
  116. // uni.$u.toast("修改成功");
  117. // } else {
  118. // uni.$u.toast("修改失败");
  119. // }
  120. });
  121. }
  122. wx.hideLoading();
  123. wx.showToast({
  124. title: "上传成功",
  125. icon: "success",
  126. duration: 3000,
  127. });
  128. },
  129. fail: function (a) {
  130. wx.hideLoading();
  131. wx.showToast({
  132. title: "上传失败",
  133. icon: "none",
  134. duration: 3000,
  135. });
  136. },
  137. });
  138. },
  139. bindblur(e) {
  140. console.log(e);
  141. let userName = e.detail.value;
  142. updateWxUser({ ...this.userInfo,nickName: userName}).then((res) => {
  143. this.$store.commit("changeUseinf", userInfo);
  144. console.log(res);
  145. });
  146. },
  147. bindinput(e) {
  148. console.log(e);
  149. },
  150. savaInfo() {
  151. let that = this;
  152. updateWxUser({ ...this.userInfo,nickname: this.userName, avatarUrl: this.avatar }).then((res) => {
  153. console.log(res);
  154. });
  155. },
  156. handleHome() {
  157. console.log("开启云上观灯", uni);
  158. logout().then((res) => {
  159. uni.$u.route("/pages/home/index");
  160. });
  161. },
  162. close() {
  163. this.show = false;
  164. // console.log('close');
  165. },
  166. open() {
  167. // this.show = false;
  168. },
  169. },
  170. };
  171. </script>
  172. <style lang="scss">
  173. .content {
  174. width: 100%;
  175. height: 100vh;
  176. position: relative;
  177. background: url(https://4dscene.4dage.com/new4dkk/deng/static/img/bg03@2x.png)
  178. 100% 100% no-repeat;
  179. background-size: cover;
  180. .userName {
  181. width: 100%;
  182. text-align: center;
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. }
  187. .avatarUrl {
  188. width: 126px;
  189. height: 126px;
  190. box-shadow: 0px 4px 9px 0px rgba(0, 0, 0, 0.25);
  191. border-radius: 0px 0px 0px 0px;
  192. border: 5px solid #ffffff;
  193. border-radius: 50%;
  194. margin: 146px auto 40px auto;
  195. .but {
  196. width: 100%;
  197. height: 100%;
  198. border-radius: 50%;
  199. padding: 0;
  200. .refreshIcon {
  201. width: 100%;
  202. border-radius: 50%;
  203. height: 100%;
  204. }
  205. }
  206. }
  207. .butText {
  208. font-weight: 400;
  209. font-size: 24px;
  210. color: #ffffff;
  211. line-height: 36px;
  212. text-shadow: 0px 0px 8px #fff9b1, 0px 0px 27px #fff9b1, 0px 0px 4px #d86332;
  213. font-style: normal;
  214. text-transform: none;
  215. position: relative;
  216. top: -110px;
  217. z-index: 10;
  218. }
  219. }
  220. </style>