index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view class="">
  3. <navBar title="我的" flex="cen" :navImg="navImg" :back="false" color="#333333" background="#FFFFFF" />
  4. <view class="container">
  5. <view class="userInfo">
  6. <u-avatar size='80' mode="aspectFill" :src="userInfo.head"
  7. @click="previewImg([userInfo.head], 0)"></u-avatar>
  8. <view class="nickname" v-if="!token" @click="login">
  9. 点击登录
  10. </view>
  11. <view class="nickname" v-else>
  12. <view class="top">
  13. {{userInfo.nickname?userInfo.nickname:"默认用户"}}
  14. </view>
  15. <view class="createAvatar" @click="updateAvatar">
  16. 制作数字分身
  17. </view>
  18. </view>
  19. <view class="" v-if="token" style="margin-left: 50px;" @click="logout">
  20. <u-icon name="setting-fill" size='30'></u-icon>
  21. </view>
  22. </view>
  23. <u-subsection :list="list" :current="curNow" activeColor="orange" fontSize="16"
  24. @change="sectionChange"></u-subsection>
  25. <!-- <swiper :current="curNow" :disable-touch="true" :disable-swipe="true" @change="swiperChange">
  26. <swiper-item> -->
  27. <view class="cenList" v-if="picList.length">
  28. <view class="swiper">
  29. <view class="xiezhenBox" v-for="(item,index) in picList">
  30. <view class="label">
  31. 任务{{item.task_id}}
  32. </view>
  33. <view class="picList" v-if="item.state">
  34. <view class="resImg" v-for="(item1,index1) in item.images">
  35. <image :src="item1" mode="aspectFill" @click="previewImg(item.images, index1)">
  36. </image>
  37. </view>
  38. </view>
  39. <view class="picList" v-else>
  40. <view class="wait">
  41. <image src="/static/images/loading2.gif" mode="aspectFill">
  42. </image>
  43. <view class="txt">
  44. 图片生成中(预计20分钟左右生成)...
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <u-loadmore :status="status" v-if="picList.length!=0" />
  50. </view>
  51. </view>
  52. <view class="" v-else style="margin-top: 100rpx;">
  53. <u-empty mode="data" text="暂无数据" icon="../../../../static/empty.png">
  54. </u-empty>
  55. </view>
  56. <!-- </swiper-item>
  57. <swiper-item>
  58. tab2
  59. </swiper-item>
  60. </swiper> -->
  61. <!-- <u-tabbar activeColor="orange" :value="value" :placeholder="false" @change="" :fixed="false"
  62. :safeAreaInsetBottom="false">
  63. <u-tabbar-item @click="toGenPic" text="首页" icon="home"></u-tabbar-item>
  64. <u-tabbar-item text="我的" icon="account"></u-tabbar-item>
  65. </u-tabbar> -->
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import {
  71. wxAuthLoginReq,
  72. taskList,
  73. getUserInfo
  74. } from '@/api/genPic/index.js'
  75. export default {
  76. data() {
  77. return {
  78. value: 1,
  79. status: 'nomore',
  80. // list: ['我的写真', '我的喜欢'],
  81. list: ['我的写真'],
  82. curNow: 0,
  83. userInfo: uni.getStorageSync('userInfo'),
  84. token: uni.getStorageSync('token'),
  85. picList: []
  86. }
  87. },
  88. components: {
  89. // tabCom
  90. },
  91. async onShow() {
  92. this.getTaskList()
  93. let res = await getUserInfo()
  94. console.log('用户信息返回值:', res);
  95. if (res.code == 0) {
  96. this.userInfo = res.data
  97. uni.setStorageSync('userInfo', res.data)
  98. }
  99. },
  100. onShareAppMessage(params) {
  101. if (params.from === 'button' || params.from === 'menu') {
  102. return {
  103. title: '思维定制相机-我的',
  104. imageUrl: '',
  105. path: '/pages/my/index',
  106. mpId: this.$appId,
  107. type: this.$shareType,
  108. }
  109. }
  110. },
  111. computed: {
  112. },
  113. methods: {
  114. logout() {
  115. let _this = this
  116. uni.showModal({
  117. title: '确定退出登录?',
  118. showCancel: true,
  119. cancelColor: '#999',
  120. confirmColor: '#F7790C',
  121. success: function(res) {
  122. if (res.confirm) {
  123. uni.clearStorageSync()
  124. _this.$toast('退出登录成功')
  125. setTimeout(() => {
  126. uni.reLaunch({
  127. url: '/pages/my/index'
  128. })
  129. }, 1500)
  130. } else if (res.cancel) {
  131. console.log('用户点击取消');
  132. }
  133. },
  134. fail: function(res) {
  135. }
  136. })
  137. },
  138. toSet() {
  139. uni.navigateTo({
  140. url: '/pages/set/index'
  141. })
  142. },
  143. //点击预览图片
  144. previewImg(list, index) {
  145. uni.previewImage({
  146. current: index,
  147. urls: list, //存放图片的数组
  148. loop: true,
  149. indicator: 'default'
  150. })
  151. },
  152. updateAvatar() {
  153. uni.navigateTo({
  154. url: '/pages/genDigitalFenshen/index'
  155. })
  156. },
  157. async getTaskList() {
  158. let res = await taskList()
  159. if (res.code == 0) {
  160. this.picList = res.data.reverse()
  161. console.log('任务列表返回值:', res, this.picList);
  162. } else {
  163. this.$toast(res.message)
  164. }
  165. },
  166. sectionChange(index) {
  167. this.curNow = index;
  168. },
  169. swiperChange(e) {
  170. // this.curNow = e.detail.current
  171. },
  172. toGenPic() {
  173. uni.navigateTo({
  174. url: '/pages/selAndGenPage/index'
  175. })
  176. },
  177. toMyPage() {
  178. uni.navigateTo({
  179. url: '/pages/my/index'
  180. })
  181. },
  182. login() {
  183. let _this = this
  184. uni.showLoading({
  185. title: '登录中...'
  186. })
  187. uni.login({
  188. provider: 'weixin',
  189. success: async (res) => {
  190. if (res.errMsg == 'login:ok') {
  191. let parmas = {
  192. code: res.code,
  193. }
  194. console.log('登录所传的parmas参数:', parmas);
  195. let res1 = await wxAuthLoginReq(parmas)
  196. if (res1.code == 0) {
  197. _this.userInfo = res1.data.user_info
  198. console.log('登录返回的用户信息:', _this.userInfo);
  199. uni.hideLoading()
  200. uni.setStorageSync('token', res1.data.token)
  201. uni.setStorageSync('userInfo', res1.data.user_info)
  202. _this.$toast('登录成功')
  203. setTimeout(() => {
  204. uni.reLaunch({
  205. url: '/pages/my/index'
  206. })
  207. }, 1500)
  208. } else {
  209. uni.showToast({
  210. title: res1.message,
  211. icon: 'none'
  212. })
  213. }
  214. }
  215. }
  216. });
  217. },
  218. }
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. @import "./index.scss";
  223. </style>