bindaccount.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view class="home">
  7. <view class="card" v-if="!loading">
  8. <view class="head">
  9. <image :src="platform.platform_icon" mode=""></image>
  10. <span>{{platform.platform_name}}账号绑定</span>
  11. </view>
  12. <view class="body">
  13. <view>
  14. <uni-forms :modelValue="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
  15. <uni-forms-item name="name" required label="昵称">
  16. <uni-easyinput type="text" v-model="formData.platform_nickname" placeholder="请填写账号昵称">
  17. </uni-easyinput>
  18. </uni-forms-item>
  19. <uni-forms-item name="numberfans" required label="粉丝数">
  20. <uni-easyinput type="number" v-model="formData.fans_count" placeholder="请填写粉丝数量">
  21. </uni-easyinput>
  22. </uni-forms-item>
  23. <uni-forms-item name="home_link" required label=" " label-width='10'>
  24. <uni-easyinput class="home-link" type="text" v-model="formData.home_page_url"
  25. placeholder="请填写个人主页链接">
  26. </uni-easyinput>
  27. </uni-forms-item>
  28. <view style="margin-top: 40rpx;">
  29. <uni-forms-item name="home_img" required label="主页截图">
  30. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1"
  31. v-model="imageData" @chooseSuccess="ceshiChooseSuccess">
  32. </htz-image-upload>
  33. </uni-forms-item>
  34. </view>
  35. </uni-forms>
  36. <view class="heng-line"></view>
  37. <button class="btn1" @click="submitForm('form')">
  38. 确认绑定</button>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import mvBar from "@/components/mys_navBar/mysNavBar";
  47. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  48. import getPolicyEncode from '@/components/obs/getPolicy.js';
  49. import getSignature from '@/components/obs/GetSignature.js';
  50. export default {
  51. components: {
  52. mvBar,
  53. htzImageUpload,
  54. },
  55. data() {
  56. return {
  57. navH: getApp().globalData.navHeight,
  58. loading: true,
  59. accountId: '',
  60. platform: {
  61. platform_id: '',
  62. platform_name: '',
  63. platform_icon: '',
  64. },
  65. isBind: true,
  66. imageData: [],
  67. formData: {
  68. platform_nickname: '',
  69. fans_count: '',
  70. home_page_url: '',
  71. },
  72. mysNavConfig: {
  73. /* 开启单页显示首页图标 */
  74. isHome: true,
  75. /* 固定导航 */
  76. navFixed: true,
  77. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  78. navTitle: {
  79. text: "社媒账号绑定",
  80. color: "",
  81. fontSize: "32rpx", // px upx rpx
  82. fontWeight: "normal", // 100 - 700
  83. },
  84. btnType: "type2",
  85. onLeftClick: '',
  86. /* type2 按钮 */
  87. type2Config: {
  88. // 左图标
  89. leftPath: "/static/img/png2.png",
  90. // 右图标
  91. rightPath: "/static/img/png4.png",
  92. // 圆角
  93. radius: "40rpx",
  94. },
  95. },
  96. }
  97. },
  98. onReady() {},
  99. async onShow() {
  100. this.loading = true;
  101. uni.showLoading({
  102. title: '加载中'
  103. });
  104. await this.getinfo();
  105. if (!this.isBind) {
  106. await this.getaccount()
  107. };
  108. this.loading = false;
  109. uni.hideLoading();
  110. },
  111. onLoad() {},
  112. onLoad(options) {
  113. this.platform.platform_id = parseInt(options.platform_id)
  114. if (options.account_id) {
  115. this.accountId = parseInt(options.account_id)
  116. this.isBind = false
  117. }
  118. },
  119. methods: {
  120. // 默认信息表,获取平台logo
  121. getinfo() {
  122. return this.$https.get('/youngee/c/g/get-info-tables')
  123. .then(res => {
  124. let list = res.data.data.ThirdPlatform
  125. for (var i = 0; i < list.length; ++i) {
  126. if (list[i].id == this.platform.platform_id) {
  127. this.platform.platform_icon = list[i].platform_icon
  128. this.platform.platform_name = list[i].platform_name
  129. }
  130. }
  131. })
  132. },
  133. getaccount() {
  134. return this.$https.get('/youngee/c/t/g/get-talent-account')
  135. .then(res => {
  136. console.log(res)
  137. if (res.data.code !== -3) {
  138. this.account = res.data.data
  139. this.imageData = []
  140. for (var i = 0; i < this.account.length; i++) {
  141. if (this.platform.platform_id == this.account[i].platform_id) {
  142. this.formData.platform_nickname = this.account[i].platform_nickname
  143. this.formData.fans_count = this.account[i].fans_count
  144. this.formData.home_page_url = this.account[i].home_page_url
  145. this.imageData.push(this.account[i].home_page_capture_url);
  146. }
  147. }
  148. }
  149. })
  150. },
  151. /**
  152. * 手动提交
  153. * @param {Object} form
  154. */
  155. submitForm(form) {
  156. const urlReg =
  157. /(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%$#_]*)?/
  158. if (!urlReg.test(this.formData.home_page_url)) {
  159. uni.showToast({
  160. title: '主页链接格式不正确',
  161. icon: 'none'
  162. })
  163. return
  164. }
  165. let that = this
  166. uni.showModal({
  167. title: '提示',
  168. content: '请保证账号信息的准确性和真实性',
  169. success: function(res) {
  170. if (res.confirm) {
  171. that.$refs[form]
  172. .submit()
  173. .then(res => {
  174. console.log('表单的值:', res)
  175. that.formData.home_page_capture_url = that.imageData[0]
  176. if (that.isBind) {
  177. that.$https.post('/youngee/c/t/p/add-talent-account', {
  178. platform_id: that.platform.platform_id,
  179. platform_nickname: that.formData.platform_nickname,
  180. home_page_url: that.formData.home_page_url,
  181. fans_count: that.formData.fans_count,
  182. home_page_capture_url: that.formData
  183. .home_page_capture_url,
  184. })
  185. .then(res => {
  186. console.log(res)
  187. if (res.data.code == 0) {
  188. uni.navigateBack()
  189. } else {
  190. let msg = res.data.msg
  191. uni.showToast({
  192. title: msg,
  193. icon: 'none',
  194. duration: 2000
  195. });
  196. }
  197. })
  198. } else {
  199. that.$https.post('/youngee/c/t/p/update-talent-account', {
  200. account_id: that.accountId,
  201. platform_id: that.platform.platform_id,
  202. platform_nickname: that.formData.platform_nickname,
  203. home_page_url: that.formData.home_page_url,
  204. fans_count: that.formData.fans_count,
  205. home_page_capture_url: that.formData
  206. .home_page_capture_url,
  207. })
  208. .then(res => {
  209. console.log(res)
  210. if (res.data.code == 0) {
  211. uni.navigateBack()
  212. } else {
  213. let msg = res.data.msg
  214. uni.showToast({
  215. title: msg,
  216. icon: 'none',
  217. duration: 2000
  218. });
  219. }
  220. })
  221. }
  222. })
  223. .catch(errors => {
  224. console.error('验证失败:', errors)
  225. uni.showToast({
  226. title: '请填写所有信息',
  227. icon: 'none'
  228. })
  229. })
  230. } else if (res.cancel) {
  231. console.log('用户点击取消');
  232. }
  233. }
  234. });
  235. },
  236. exit() {
  237. uni.navigateBack()
  238. },
  239. ceshiChooseSuccess(tempFilePaths, e) { //选择图片返回
  240. console.log('ceshiChooseSuccess', tempFilePaths, e);
  241. if (e == 0) {
  242. this.store = 'talent_upload/' + this.guid() + '.png'
  243. // this.store = 'talent_upload/guide.png'
  244. } else if (e == 1) {
  245. this.store = 'talent_upload/' + this.guid() + '.mp4'
  246. }
  247. /****************
  248. 以下代码是自定义上传逻辑,仅供参考
  249. ***************/
  250. this.imgUpload(tempFilePaths);
  251. /*******************************/
  252. console.log("imgdata" + this.imageData)
  253. },
  254. imgUpload(tempFilePaths) {
  255. let that = this
  256. console.log('imgUpload', tempFilePaths)
  257. let config = {
  258. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  259. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  260. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  261. };
  262. let fileName = this.store; //指定上传到OBS桶中的对象名
  263. let OBSPolicy = { //设定policy内容
  264. "expiration": "2089-12-31T12:00:00.000Z",
  265. "conditions": [{
  266. "bucket": "horastar"
  267. }, //Bucket name
  268. // {"bucket": "goin"},
  269. {
  270. 'key': fileName
  271. }
  272. ]
  273. }
  274. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  275. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  276. uni.uploadFile({
  277. //url: config.EndPoint,
  278. url: config.EndPoint,
  279. filePath: tempFilePaths[0],
  280. name: 'file',
  281. formData: {
  282. 'AccessKeyID': config.AccessKeyId,
  283. 'policy': policyEncoded,
  284. 'signature': signature,
  285. 'key': fileName,
  286. },
  287. success: function(res) {
  288. console.log(res.statusCode); //打印响应状态码
  289. if (res.statusCode == '204') {
  290. that.imageData.push(config.EndPoint + '/' + fileName);
  291. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  292. console.log(obs_url)
  293. that.formData.home_img = obs_url
  294. uni.showToast({
  295. title: '上传成功',
  296. icon: '成功'
  297. });
  298. } else {
  299. uni.showToast({
  300. title: '上传失败',
  301. icon: '失败'
  302. });
  303. }
  304. },
  305. fail: function(e) {
  306. console.log(e);
  307. uni.showToast({
  308. title: '上传失败22222',
  309. icon: '失败'
  310. });
  311. }
  312. })
  313. },
  314. guid() {
  315. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  316. var r = Math.random() * 16 | 0,
  317. v = c == 'x' ? r : (r & 0x3 | 0x8);
  318. return v.toString(16);
  319. });
  320. },
  321. },
  322. }
  323. </script>
  324. <style>
  325. .uni-easyinput__content-input {
  326. font-size: 24rpx !important;
  327. }
  328. /deep/.uni-forms-item__inner {
  329. border-bottom: none !important;
  330. margin-bottom: 0 !important;
  331. }
  332. .uni-forms-item__label {
  333. font-size: 30rpx;
  334. display: flex;
  335. flex-shrink: 0;
  336. box-sizing: border-box;
  337. flex-direction: row;
  338. align-items: center;
  339. width: 65px;
  340. padding: 5px 0;
  341. /* height: 36px; */
  342. }
  343. </style>
  344. <style lang="scss" scoped>
  345. .card {
  346. padding: 24rpx;
  347. margin-top: 30rpx;
  348. border: 1rpx solid #F0D232;
  349. background-color: #ffffff;
  350. margin: 0 10rpx;
  351. }
  352. .head {
  353. padding-top: 5%;
  354. padding: 0 0 0 1%;
  355. height: 80rpx;
  356. margin-top: 2%;
  357. }
  358. .head span {
  359. color: #333333;
  360. font-size: 80%;
  361. font-weight: 550;
  362. text-indent: 2em;
  363. }
  364. .head image {
  365. vertical-align: middle;
  366. width: 50rpx;
  367. height: 50rpx;
  368. display: inline-block;
  369. padding-right: 14rpx;
  370. }
  371. .home-link {
  372. /deep/.uni-easyinput__content-input {
  373. background-color: #EBEBEB;
  374. border-radius: 15rpx;
  375. }
  376. }
  377. .heng-line {
  378. margin-top: 60rpx;
  379. margin-bottom: 50rpx;
  380. border-bottom: 1rpx solid #DCDCDC;
  381. }
  382. .signupbtn p {
  383. font-size: 30rpx;
  384. }
  385. .exit-btn {
  386. width: 200rpx;
  387. text-align: center;
  388. padding: 10rpx 30rpx;
  389. background-color: #C0C0C0;
  390. border: 0;
  391. border-radius: 10rpx;
  392. color: #FFFFFF;
  393. font-size: 30rpx;
  394. line-height: 180%;
  395. }
  396. .btn1 {
  397. margin: 30rpx;
  398. font-size: 35rpx;
  399. color: #000;
  400. background-color: #F0D232;
  401. border: none;
  402. border-radius: 0;
  403. }
  404. .uni-input-placeholder {
  405. font-size: 24rpx !important;
  406. }
  407. /deep/.uni-date-x--border {
  408. border: 0px solid #dcdfe6 !important;
  409. }
  410. /deep/.is-input-border {
  411. border: 0px solid #c8c7cc !important;
  412. }
  413. </style>