uploadlink.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view style="margin-top: 160rpx;"></view>
  6. <view @click="toRecord()">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 30rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <!-- 多行输入框 -->
  15. <view style="margin: 40rpx;font-size: 32rpx">
  16. <p style="margin-bottom: 20rpx;">上传链接</p>
  17. <textarea v-model="link_url" style="height: 50px" placeholder="请删除中文等其他字符,仅输入https://或http://开头的发布链接,样叽会对此进行质检~" />
  18. </view>
  19. <view style="margin: 0 40rpx;">
  20. <p style="margin-bottom: 20rpx;">上传作品收录/发布截图</p>
  21. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  22. @chooseSuccess="ceshiChooseSuccess1">
  23. </htz-image-upload>
  24. </view>
  25. <view class="signup">
  26. <button type="default" class="but1" :loading="loading" @click="submit()">
  27. 提交链接</button>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import mvBar from "@/components/mys_navBar/mysNavBar";
  33. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  34. import getPolicyEncode from '@/components/obs/getPolicy.js';
  35. import getSignature from '@/components/obs/GetSignature.js';
  36. export default {
  37. components: {
  38. mvBar,
  39. htzImageUpload,
  40. },
  41. data() {
  42. return {
  43. taskId: "",
  44. link_url: "",
  45. imageData: [],
  46. linkStatus: "",
  47. mysNavConfig: {
  48. /* 开启单页显示首页图标 */
  49. isHome: true,
  50. /* 固定导航 */
  51. navFixed: true,
  52. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  53. navTitle: {
  54. text: "上传链接",
  55. color: "",
  56. fontSize: "32rpx", // px upx rpx
  57. fontWeight: "normal", // 100 - 700
  58. },
  59. btnType: "type2",
  60. onLeftClick: '',
  61. /* type2 按钮 */
  62. type2Config: {
  63. // 左图标
  64. leftPath: "/static/img/png2.png",
  65. // 右图标
  66. rightPath: "/static/img/png4.png",
  67. // 圆角
  68. radius: "40rpx",
  69. },
  70. },
  71. }
  72. },
  73. onLoad(options) {
  74. let data = options.textObj.replace(/""/g, "");
  75. data = JSON.parse(decodeURIComponent(data))
  76. this.taskId = data.taskId
  77. this.linkStatus = data.linkStatus
  78. this.getLink()
  79. },
  80. methods: {
  81. getLink() {
  82. this.$https.get('/youngee/c/t/g/get-unsubmit-task-link' +
  83. "?" +
  84. "task_id" +
  85. "=" +
  86. this.taskId)
  87. .then(res => {
  88. console.log(res)
  89. if (res.data.data != null) {
  90. this.imageData.push(res.data.data.photo_url)
  91. this.link_url = res.data.data.link_url
  92. }
  93. })
  94. },
  95. toRecord() {
  96. var data = {
  97. taskId: this.taskId,
  98. };
  99. data = JSON.stringify(data)
  100. uni.navigateTo({
  101. url: '/pages/workspace/linkrecord?textObj=' + encodeURIComponent(data)
  102. });
  103. },
  104. submit() {
  105. // 校验
  106. if (this.link_url == "" || (this.link_url.substring(0, 8) != "https://" && this.link_url.substring(0, 7) != "http://")) {
  107. uni.showToast({
  108. title: '请输入正确的发布链接',
  109. icon: 'none'
  110. })
  111. return
  112. }
  113. if (this.imageData.length == 0) {
  114. uni.showToast({
  115. title: '请上传收录/发布截图',
  116. icon: 'none'
  117. })
  118. return
  119. }
  120. // 调用添加链接接口
  121. this.$https.post('/youngee/c/t/p/add-task-link', {
  122. task_id: this.taskId,
  123. link_url: this.link_url,
  124. photo_url: this.imageData[0],
  125. })
  126. .then(res => {
  127. console.log(res)
  128. uni.navigateBack()
  129. })
  130. },
  131. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  132. console.log('ceshiChooseSuccess', tempFilePaths, e);
  133. if (e == 0) {
  134. this.store = 'talent_upload/' + this.guid() + '.png'
  135. } else if (e == 1) {
  136. this.store = 'talent_upload/' + this.guid() + '.mp4'
  137. }
  138. /****************
  139. 以下代码是自定义上传逻辑,仅供参考
  140. ***************/
  141. this.imgUpload1(tempFilePaths);
  142. /*******************************/
  143. console.log("imgdata" + this.imageData)
  144. },
  145. imgUpload1(tempFilePaths) {
  146. let that = this
  147. console.log('imgUpload', tempFilePaths)
  148. let config = {
  149. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  150. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  151. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  152. };
  153. let fileName = this.store; //指定上传到OBS桶中的对象名
  154. // let fileName = "talent_upload/icon-arrow-right.png"
  155. let OBSPolicy = { //设定policy内容
  156. "expiration": "2089-12-31T12:00:00.000Z",
  157. "conditions": [{
  158. "bucket": "horastar"
  159. }, //Bucket name
  160. // {"bucket": "goin"},
  161. {
  162. 'key': fileName
  163. }
  164. ]
  165. }
  166. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  167. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  168. uni.uploadFile({
  169. //url: config.EndPoint,
  170. url: config.EndPoint,
  171. filePath: tempFilePaths[0],
  172. name: 'file',
  173. formData: {
  174. 'AccessKeyID': config.AccessKeyId,
  175. 'policy': policyEncoded,
  176. 'signature': signature,
  177. 'key': fileName,
  178. },
  179. success: function(res) {
  180. console.log(res.statusCode); //打印响应状态码
  181. if (res.statusCode == '204') {
  182. that.imageData.push(config.EndPoint + '/' + fileName);
  183. console.log('上传图片成功', res)
  184. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  185. console.log(obs_url)
  186. // that.formData.home_img = obs_url
  187. uni.showToast({
  188. title: '上传成功',
  189. icon: '成功'
  190. });
  191. } else {
  192. console.log('上传图片失败', res)
  193. uni.showToast({
  194. title: '上传失败',
  195. icon: '失败'
  196. });
  197. }
  198. },
  199. fail: function(e) {
  200. console.log(e);
  201. uni.showToast({
  202. title: '上传失败22222',
  203. icon: '失败'
  204. });
  205. }
  206. })
  207. },
  208. guid() {
  209. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  210. var r = Math.random() * 16 | 0,
  211. v = c == 'x' ? r : (r & 0x3 | 0x8);
  212. return v.toString(16);
  213. });
  214. },
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .signup {
  220. box-shadow: 0rpx 5rpx 40rpx #ccc;
  221. width: 100%;
  222. position: fixed;
  223. bottom: 0rpx;
  224. display: flex;
  225. height: 90rpx;
  226. padding-top: 2%;
  227. background-color: #FFFFFF;
  228. }
  229. .but1 {
  230. width: 60%;
  231. background-color: #f2d22d;
  232. border-radius: 20rpx;
  233. font-size: 36rpx;
  234. line-height: 200%;
  235. letter-spacing: 10rpx;
  236. font-weight: 500;
  237. height: 80%;
  238. &.on {
  239. background-color: #C0C0C0;
  240. }
  241. }
  242. </style>