my.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="my-v" v-if="loading">
  3. <view class="u-flex user-box u-p-l-20 u-p-r-10 u-p-b-20">
  4. <view class="u-m-r-10">
  5. <u-avatar size="127" @click='chooseAvatar' :src='avatarSrc'></u-avatar>
  6. </view>
  7. <view class="u-flex-1 f-right" @click="personalPage('/pages/my/personalData/index')">
  8. <view class="u-font-36 u-m-l-16">{{baseInfo.realName}}</view>
  9. <view class="u-m-l-10 u-p-10">
  10. <u-icon name="arrow-right" color="#969799" size="28"></u-icon>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="u-m-t-20 my-group-box">
  15. <view class="my-group-box-inner">
  16. <u-cell-group :border="false" class="cell-group">
  17. <u-cell-item :title="$t('app.my.organization')"
  18. @click="openPage('/pages/my/business/index','Organize')" :title-style="titleStyle">
  19. <template #icon>
  20. <text class="icon-ym icon-ym-zuzhi u-m-r-16 u-font-32 my-list" />
  21. </template>
  22. </u-cell-item>
  23. <u-cell-item :title="$t('app.my.position')" @click="openPage('/pages/my/business/index','Position')"
  24. :title-style="titleStyle">
  25. <template #icon>
  26. <text class="icon-ym icon-ym-position1 u-m-r-16 u-font-32 my-list" />
  27. </template>
  28. </u-cell-item>
  29. <u-cell-item :title="$t('app.my.subordinates')" @click="openPage('/pages/my/subordinate/index')"
  30. :title-style="titleStyle">
  31. <template #icon>
  32. <text class="icon-ym icon-ym-generator-section u-m-r-16 u-font-32 my-list" />
  33. </template>
  34. </u-cell-item>
  35. <u-cell-item :title="$t('app.my.entrustedAgency')" @click="openPage('/pages/my/entrustAgent/index')"
  36. :title-style="titleStyle">
  37. <template #icon>
  38. <text class="icon-ym icon-ym-header-role-toggle u-m-r-16 u-font-32 my-list" />
  39. </template>
  40. </u-cell-item>
  41. <u-cell-item :title="$t('app.my.switchIdentity')" @click="selectShow = true"
  42. v-if="userInfo.standingList?.length > 1" :title-style="titleStyle">
  43. <template #icon>
  44. <text class="icon-ym icon-ym-header-role-toggle u-m-r-16 u-font-32 my-list" />
  45. </template>
  46. </u-cell-item>
  47. <!-- #ifndef H5 -->
  48. <u-cell-item :title="$t('app.my.scanCode')" @click="scanCode()" :title-style="titleStyle">
  49. <template #icon>
  50. <text class="icon-ym icon-ym-scanCode1 u-m-r-16 u-font-32 my-list" />
  51. </template>
  52. </u-cell-item>
  53. <!-- #endif -->
  54. <!-- #ifdef APP-PLUS -->
  55. <u-cell-item :title="$t('app.my.accountSecurity')"
  56. @click="openPage('/pages/my/accountSecurity/index')" :title-style="titleStyle">
  57. <template #icon>
  58. <text class="icon-ym icon-ym-zhanghao u-m-r-16 u-font-32 my-list" />
  59. </template>
  60. </u-cell-item>
  61. <!-- #endif -->
  62. <u-cell-item :title="$t('app.my.setting')" @click="openPage('/pages/my/settings/index')"
  63. :title-style="titleStyle" :border-bottom="false">
  64. <template #icon>
  65. <text class="icon-ym icon-ym-shezhi u-m-r-16 u-font-32 my-list" />
  66. </template>
  67. </u-cell-item>
  68. </u-cell-group>
  69. </view>
  70. </view>
  71. <view class="u-p-t-20">
  72. <view class="logout-cell" hover-class="u-cell-hover" @click="logout">{{$t('app.my.logOut')}}</view>
  73. </view>
  74. <u-select v-model="selectShow" :list="selectList" mode="single-column" value-name='id' label-name='name'
  75. :default-value="defaultValue" @confirm="confirm"></u-select>
  76. </view>
  77. </template>
  78. <script>
  79. import IndexMixin from './mixin.js'
  80. import {
  81. UpdateAvatar,
  82. UserSettingInfo,
  83. setMajor
  84. } from '@/api/common'
  85. import chat from '@/libs/chat.js'
  86. import {
  87. useUserStore
  88. } from '@/store/modules/user'
  89. import {
  90. useChatStore
  91. } from '@/store/modules/chat'
  92. export default {
  93. mixins: [IndexMixin],
  94. data() {
  95. return {
  96. defaultValue: [],
  97. selectList: [],
  98. selectShow: false,
  99. titleStyle: {
  100. color: '#606266'
  101. },
  102. userInfo: '',
  103. avatarSrc: '',
  104. baseInfo: {},
  105. loading: false,
  106. cellItemColor: ['#6071F5', '#F4A02F', '#2B7FF0', '#4CBF2A']
  107. }
  108. },
  109. computed: {
  110. baseURL() {
  111. return this.define.comUploadUrl
  112. },
  113. baseURL2() {
  114. return this.define.baseURL
  115. },
  116. token() {
  117. return uni.getStorageSync('token')
  118. },
  119. report() {
  120. return this.define.report
  121. }
  122. },
  123. onLoad() {
  124. const chatStore = useChatStore()
  125. if (!chatStore.getSocket) chat.initSocket()
  126. },
  127. onShow() {
  128. UserSettingInfo().then(res => {
  129. this.baseInfo = res.data || {}
  130. this.avatarSrc = this.baseURL2 + this.baseInfo.avatar
  131. this.loading = true
  132. })
  133. this.setStanding()
  134. },
  135. methods: {
  136. confirm(e) {
  137. if (e[0].index == this.defaultValue[0]) return
  138. let data = {
  139. majorId: e[0].value,
  140. majorType: "Standing",
  141. menuType: 1,
  142. }
  143. setMajor(data).then(res => {
  144. this.$u.toast(res.msg)
  145. this.getCurrentUser()
  146. })
  147. },
  148. setStanding() {
  149. this.selectShow = false
  150. this.userInfo = uni.getStorageSync('userInfo') || {}
  151. this.selectList = []
  152. this.selectList = JSON.parse(JSON.stringify(this.userInfo.standingList))
  153. this.selectList.forEach((o, i) => {
  154. o.id = Number(this.selectList[i].id)
  155. })
  156. this.defaultValue = [this.selectList.findIndex(o => o.currentStanding)];
  157. },
  158. getCurrentUser() {
  159. const userStore = useUserStore()
  160. userStore.getCurrentUser().then(() => {
  161. this.setStanding()
  162. })
  163. },
  164. chooseAvatar() {
  165. uni.chooseImage({
  166. count: 1,
  167. sizeType: ['original', 'compressed'],
  168. success: (res) => {
  169. // #ifdef H5
  170. let isAccept = new RegExp('image/*').test(res.tempFiles[0].type)
  171. if (!isAccept) return this.$u.toast(`请上传图片`)
  172. // #endif
  173. let tempFilePaths = res.tempFilePaths[0]
  174. uni.uploadFile({
  175. url: this.baseURL + 'userAvatar',
  176. filePath: tempFilePaths,
  177. name: 'file',
  178. header: {
  179. 'Authorization': this.token
  180. },
  181. success: (uploadFileRes) => {
  182. let data = JSON.parse(uploadFileRes.data)
  183. if (data.code === 200) {
  184. UpdateAvatar(data.data.name).then(res => {
  185. this.$u.toast('头像更换成功')
  186. this.avatarSrc = this.baseURL2 + data.data.url
  187. })
  188. } else {
  189. this.$u.toast(data.msg)
  190. }
  191. },
  192. fail: (err) => {
  193. this.$u.toast('头像更换失败')
  194. }
  195. });
  196. }
  197. });
  198. },
  199. openPage(path, type) {
  200. if (!path) return
  201. let url = !!type ? path + '?majorType=' + type : path
  202. uni.navigateTo({
  203. url: url
  204. })
  205. },
  206. personalPage(path) {
  207. if (!path) return
  208. uni.navigateTo({
  209. url: path + '?baseInfo=' + encodeURIComponent(JSON
  210. .stringify(this.baseInfo))
  211. })
  212. },
  213. isJSON(str) {
  214. try {
  215. var obj = JSON.parse(str);
  216. if (typeof obj == 'object' && obj) {
  217. return true;
  218. } else {
  219. return false;
  220. }
  221. } catch (e) {
  222. return false;
  223. }
  224. },
  225. logout() {
  226. uni.showModal({
  227. title: '提示',
  228. content: '确定退出当前账号吗?',
  229. success: res => {
  230. if (res.confirm) {
  231. const userStore = useUserStore()
  232. userStore.logout().then(() => {
  233. uni.closeSocket()
  234. uni.reLaunch({
  235. url: '/pages/login/index'
  236. })
  237. })
  238. this.removeAccount()
  239. }
  240. }
  241. })
  242. },
  243. removeAccount() {
  244. let model = uni.getStorageSync('rememberAccount')
  245. if (!model.remember) {
  246. model.account = ''
  247. model.password = ''
  248. model.remember = false
  249. uni.setStorageSync('rememberAccount', model)
  250. }
  251. },
  252. scanCode() {
  253. uni.scanCode({
  254. success: res => {
  255. let url = ""
  256. if (this.isJSON(res.result.trim())) {
  257. const result = JSON.parse(res.result.trim())
  258. if (result.t === 'ADP') {
  259. let config = {
  260. isPreview: 1,
  261. moduleId: result.id,
  262. previewType: result.previewType
  263. }
  264. url = '/pages/apply/dynamicModel/index?config=' + this.jnpf.base64.encode(JSON
  265. .stringify(config))
  266. }
  267. if (result.t === 'DFD') {
  268. url = '/pages/apply/dynamicModel/scanForm?config=' + JSON.stringify(result)
  269. }
  270. if (result.t === 'WFP') {
  271. url = '/pages/workFlow/scanForm/index?config=' + JSON.stringify(result)
  272. }
  273. if (result.t === 'report') {
  274. let url_ =
  275. `${this.report}/preview.html?id=${result.id}&token=${this.token}&page=1&from=menu`
  276. url = '/pages/apply/externalLink/index?url=' + encodeURIComponent(url_) +
  277. '&fullName= ' + result.fullName
  278. }
  279. if (result.t === 'portal') {
  280. url = '/pages/portal/scanPortal/index?id=' + result.id
  281. }
  282. if (result.t === 'login') {
  283. url = '/pages/login/scanLogin?id=' + result.id
  284. }
  285. } else {
  286. url = '/pages/my/scanResult/index?result=' + res.result
  287. }
  288. uni.navigateTo({
  289. url,
  290. fail: (err) => {
  291. this.$u.toast("暂无此页面")
  292. }
  293. })
  294. }
  295. });
  296. }
  297. }
  298. }
  299. </script>
  300. <style lang="scss">
  301. page {
  302. background-color: #f0f2f6;
  303. }
  304. .my-v {
  305. :deep(.u-cell) {
  306. height: 112rpx;
  307. padding: 0;
  308. }
  309. .my-group-box {
  310. .my-group-box-inner {
  311. background-color: #fff;
  312. .cell-group {
  313. padding: 0 20rpx;
  314. .icon-ym-zuzhi {
  315. color: #6071F5;
  316. }
  317. .icon-ym-position1 {
  318. color: #2B7FF0;
  319. }
  320. .icon-ym-generator-section {
  321. color: #F4A02F;
  322. }
  323. .icon-ym-shezhi {
  324. color: #4CBF2A;
  325. }
  326. }
  327. }
  328. }
  329. .user-box {
  330. background-color: #fff;
  331. }
  332. .logout-cell {
  333. text-align: center;
  334. font-size: 32rpx;
  335. height: 108rpx;
  336. background-color: #fff;
  337. color: #D82828;
  338. line-height: 98rpx;
  339. font-family: PingFang SC;
  340. }
  341. .f-right {
  342. display: flex;
  343. flex-direction: row;
  344. justify-content: space-between;
  345. align-items: center;
  346. text-align: center;
  347. }
  348. }
  349. </style>