uploadlink.vue 6.8 KB

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