bindaccount.vue 12 KB

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