index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <home-frame @toPath="toPath">
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1">
  6. <image class="image"
  7. :src="userInfo.logo_url&&userInfo.logo_url.length>0?userInfo.logo_url[0].url:''" mode="">
  8. </image>
  9. </view>
  10. <view class="one_2">
  11. <view class="name">
  12. {{userInfo.name||'暂无'}}
  13. </view>
  14. <view class="id">
  15. <uni-icons type="phone-filled" size="15" color="var(--rgbfff)"></uni-icons>
  16. :{{userInfo.phone||'暂无'}}
  17. </view>
  18. </view>
  19. <view class="one_3" v-if="!userInfo._id">
  20. <button size="mini" @tap="toLogin()">注册/登录</button>
  21. </view>
  22. </view>
  23. <view class="two">
  24. <view class="list" v-for="(item,index) in basicInfo.account_btn" :key="index" @tap="toCommon(item)">
  25. <image class="image" :src="item.img_url&&item.img_url.length>0?item.img_url[0].url:''" mode="">
  26. </image>
  27. <view class="name">
  28. {{item.name}}
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </home-frame>
  34. </template>
  35. <script>
  36. import homeFrame from "../components/home-frame.vue";
  37. export default {
  38. components: {
  39. homeFrame
  40. },
  41. data() {
  42. return {
  43. // 基本信息
  44. basicInfo: {},
  45. // 用户信息
  46. userInfo: {},
  47. };
  48. },
  49. onLoad() {
  50. },
  51. onShow() {
  52. const that = this;
  53. that.searchBasic();
  54. },
  55. methods: {
  56. searchBasic() {
  57. const that = this;
  58. uni.getStorage({
  59. key: 'basicInfo',
  60. success: (res) => {
  61. let data = res.data
  62. data.account_btn = data.account_btn.sort((a, b) => {
  63. return a.sort - b.sort
  64. });
  65. that.$set(that, `basicInfo`, data);
  66. that.search()
  67. }
  68. })
  69. },
  70. search() {
  71. const that = this;
  72. let user = {
  73. name: that.basicInfo.name,
  74. phone: 'test',
  75. logo_url: that.basicInfo.logo_url
  76. }
  77. uni.getStorage({
  78. key: 'token',
  79. success: async (res) => {
  80. let arr = that.$jwt(res.data);
  81. let aee = await that.$api(`user/${arr._id}`, 'GET');
  82. if (aee.errcode == '0') {
  83. user._id = aee.data._id;
  84. user.id = aee.data.id;
  85. user.phone = aee.data.phone;
  86. if (aee.data && aee.data.nick_name) user.name = aee.data.nick_name;
  87. if (aee.data && aee.data.logo_url) user.logo_url = aee.data.logo_url;
  88. }
  89. },
  90. fail: (err) => {
  91. console.log(err);
  92. }
  93. })
  94. that.$set(that, `userInfo`, user)
  95. },
  96. // 注册,登录
  97. toLogin() {
  98. uni.navigateTo({
  99. url: '/pagesAccount/login/index'
  100. })
  101. },
  102. // 功能按钮跳转
  103. toCommon(e) {
  104. const that = this;
  105. if (e.is_jump == '0') {
  106. if (e.nature == 'share') {
  107. that.share()
  108. } else if (e.nature == 'logout') {
  109. uni.removeStorage({
  110. key: 'token',
  111. success: function(res) {
  112. uni.showToast({
  113. title: '退出登录成功',
  114. icon: 'none'
  115. })
  116. that.searchBasic()
  117. },
  118. fail: (err) => {
  119. console.log(err);
  120. }
  121. });
  122. }
  123. } else if (e.is_jump == '1') {
  124. that.toPath({
  125. type: e.type,
  126. route: e.route
  127. })
  128. }
  129. },
  130. // 分享
  131. share() {
  132. const that = this;
  133. let system = that.$config.system
  134. let basicInfo = that.basicInfo;
  135. if (system.uniPlatform == 'app') {
  136. uni.share({
  137. provider: "weixin",
  138. scene: "WXSceneSession",
  139. type: 0,
  140. href: "http://uniapp.dcloud.io/",
  141. title: system.appName,
  142. summary: "我正在玩益智游戏,赶紧和我一起体验吧",
  143. imageUrl: basicInfo.logo_url && basicInfo.logo_url.length > 0 ? basicInfo.logo_url[0].url :
  144. '',
  145. success: function(res) {
  146. console.log("success:" + JSON.stringify(res));
  147. },
  148. fail: function(err) {
  149. console.log("fail:" + JSON.stringify(err));
  150. }
  151. });
  152. } else if (system.uniPlatform == 'mp-weixin') {
  153. uni.showToast({
  154. title: '小程序未开通分享功能!',
  155. icon: "none"
  156. })
  157. }
  158. },
  159. // 跳转页面
  160. toPath(e) {
  161. let url = `/${e.route}`;
  162. if (e.type == '0') uni.navigateTo({
  163. url
  164. })
  165. else if (e.type == '1') uni.redirectTo({
  166. url
  167. })
  168. else if (e.type == '2') uni.reLaunch({
  169. url
  170. })
  171. else if (e.type == '3') uni.switchTab({
  172. url
  173. })
  174. }
  175. },
  176. };
  177. </script>
  178. <style lang="scss">
  179. .main {
  180. background-color: var(--rgb000);
  181. display: flex;
  182. flex-direction: column;
  183. width: 100vw;
  184. height: 92vh;
  185. overflow-y: auto;
  186. .one {
  187. display: flex;
  188. padding: 2vw;
  189. margin: 0 0 10px 0;
  190. .one_1 {
  191. width: 80px;
  192. height: 80px;
  193. overflow: hidden;
  194. margin: 0 2vw 0 0;
  195. .image {
  196. width: 100%;
  197. height: 80px;
  198. overflow: hidden;
  199. border-radius: 90%;
  200. }
  201. }
  202. .one_2 {
  203. flex-grow: 1;
  204. color: var(--rgbfff);
  205. font-size: 16px;
  206. font-weight: bold;
  207. padding: 2vw 0;
  208. overflow: hidden;
  209. .name {
  210. font-size: 18px;
  211. margin: 0 0 1vw 0;
  212. background: linear-gradient(to bottom right, var(--rgbfa4), var(--rgbfff));
  213. color: transparent;
  214. background-clip: text;
  215. -webkit-background-clip: text;
  216. }
  217. }
  218. .one_3 {
  219. padding: 4vw 0;
  220. overflow: hidden;
  221. button {
  222. background-color: var(--rgbfa4);
  223. color: var(--rgbfff);
  224. }
  225. }
  226. }
  227. .two {
  228. display: flex;
  229. // justify-content: space-around;
  230. flex-wrap: wrap;
  231. padding: 0 2vw;
  232. .list {
  233. width: 22%;
  234. height: 74px;
  235. margin: 0 10px 10px 0;
  236. text-align: center;
  237. background: linear-gradient(to bottom right, var(--rgb000), var(--rgbfa4));
  238. border: 1px solid var(--rgb111);
  239. border-radius: 5px;
  240. .image {
  241. width: 20px;
  242. height: 20px;
  243. margin: 3vw 0 2vw 0;
  244. }
  245. .name {
  246. color: var(--rgbfff);
  247. font-size: 14px;
  248. }
  249. }
  250. .list:nth-child(4n) {
  251. margin: 0 0 10px 0;
  252. }
  253. }
  254. }
  255. </style>