bindaccount.vue 14 KB

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